struts逻辑标签呈现html格式,JSTL标签不 [英] struts logic tags rendering html format, JSTL tags do not

查看:109
本文介绍了struts逻辑标签呈现html格式,JSTL标签不的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在读取数据库中的一些消息并将其扔到一个jsp页面。当使用struts逻辑标签来呈现数据库中的消息时,数据库中的消息允许使用HTML格式,这意味着如果一个html标签,如< table width =99%> 在数据库消息中使用,那么当使用struts逻辑标签时它会正确地呈现这个html ...但是如果使用JSTL来呈现对象(数据库消息),那么html格式不能正确呈现。



struts逻辑标签的一个例子是:

 < div class =textTitle >< bean:write name =blahBlahfilter =falseproperty =displayObjects [1] .fieldName/>< / div> 

JSTL标签的一个例子是:

 < td width =30%class =formOpt>< c:out value =$ {pubParam.fieldName}/>:< / td> ; 

请注意,我为JSTL使用 c:out bean:write 用于struts标签..

有谁知道为什么在JSTL中html格式化没有被渲染(即从数据库消息中包含< table width =99%> )?


< JSTL c:out 默认情况下标记为escape属性中的XML。所以它可以防止从表达式变量渲染一些不需要的代码XSS。在大多数情况下,您不应该出现 c:out html内容。但有一个开关可以让你自行承担风险。

 < c:out value =$ {pubParam.fieldName}escapeXml =false/> 


I am reading some messages from a database and throwing it to a jsp page. When using struts logic tags to render the message from the database the message in the database allows HTML formatting, meaning if an html tag such as <table width="99%"> is used in the database message then it will render this html properly when using struts logic tags... however if JSTL is used to render the object (database message) then the html formatting is not rendered properly.

An example of the struts logic tags is:

<div class="textTitle"><bean:write name="blahBlah" filter="false" property="displayObjects[1].fieldName"/></div>

An example of the JSTL tag is:

<td width="30%" class="formOpt"><c:out value="${pubParam.fieldName}"/>:</td>

notice i use c:out for JSTL and bean:write for struts tag..

Does anyone know why in JSTL the html formatting is not being rendering yet thrown to the page as is (meaning including the <table width="99%"> from the database message)?

解决方案

JSTL c:out tag by default escapes XML in the value attribute. So it prevents some unwanted code XSS rendered from the expression variable. In most cases you should not c:out html content that you want to be rendered. But there's a switch that you can use on your own risk.

<c:out value="${pubParam.fieldName}" escapeXml="false"/>

这篇关于struts逻辑标签呈现html格式,JSTL标签不的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆