Java 在jsp中显示具有html代码的字符串
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20471199/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Display String having html code in jsp
提问by user3069091
This is my string:-
这是我的字符串:-
String valueofString ="<p><b>Property Location</b> <br />With a stay at Sheraton Seattle Hotel, you'll be centrally located in Seattle, steps from 5th Avenue Theater and Washington State Convention Center. This 4-star" ;
Now I need to display this string in html but html elements is printing as it is by jsp output .
现在我需要在 html 中显示这个字符串,但是 html 元素正在打印,因为它是通过 jsp 输出。
I tried like this:
我试过这样:
<c:out value="${valueofString}" escapeXml="false"/>
but it is not work for me.
但这对我不起作用。
any help would be appreciated .
任何帮助,将不胜感激 。
Thank you in advance.
先感谢您。
回答by Vignesh Vino
Add <textarea>
</textarea>
to the begining and at the end of your string.
添加<textarea>
</textarea>
到字符串的开头和结尾。
String valueofString ="<textarea><p><b>Property Location</b> <br />With a stay at Sheraton Seattle Hotel, you'll be centrally located in Seattle, steps from 5th Avenue Theater and Washington State Convention Center. This 4-star</textarea>" ;
回答by Kloe2378231
This is not ideal, but you can use scriplet to do this: http://www.tutorialspoint.com/jsp/jsp_syntax.htm
这并不理想,但您可以使用脚本来做到这一点:http://www.tutorialspoint.com/jsp/jsp_syntax.htm
<%
String valueofString ="<p><b>Property Location</b> <br />With a stay at ...";
out.write(valueofString);
%>
Something like this should be better:
这样的事情应该更好:
Java:
爪哇:
String location ="Property Location";
String detail ="With a stay at ...";
JSP:
JSP:
<p>
<b><c:out value="${location}" /></b><br/>
<c:out value="${detail}" />
</p>