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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 02:11:49  来源:igfitidea点击:

Display String having html code in jsp

javajsp

提问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>