您的位置:首页 > 其它

使用模拟器的一点心得

2009-08-25 11:28 477 查看
表单中输入了<b></b>、单引号、双引号等内容,正确保存后,列表页面、查看详情页面、编辑页面,都出现了问题不能正确显示上面的内容。

怎样才能正确显示呢?有一个办法就是在将这些内容放到Html页面上显示之前,先进行Html转义。

查看详情页面、编辑页面的Html转义方法,在Java标准框架中,使用的是Freemarker作为页面的模板技术,它内置了一个函数xhtml,就是用来对内容进行Html转义的。看下面的代码:

<tr>
<td><label>名称</label></td>
<td>${((topicCase.name)!'')?xhtml}</td>
</tr>

<tr>
<td>
<label required="true
"
>名称</label>
</td>
<td>
<input name="name"
art="textbox"
value="${((topicCase.name)!'')?xhtml}"
form_fill="true
"
required="true
"
validType="length[1,50]"
/>
</td>
</tr>


列表页面使用的是jart的grid控件,它的数据格式为json,所以我们在json序列化时进行Html转义。Java标准框架中提供了一个注解@ResponseEscape,以指明在进行json序列化时,要进行Html转义,代码如下:

@ResponseEscape
public
PaginationList<TopicCase> getList(@PaginationParam PaginationCriteria paginationCriteria,
@RequestEscape(policy=EscapePolicy.Sql) @RequestParam(required = false
) String
name,
@RequestParam(required = false
) TopicCaseState state,
@DateParam Date beginTime,
@DateParam Date endTime) {}


要使@ResponseEscape生效,还得在servlet-context.xml中进行如下配置:

<!-- Enables the Spring MVC @Controller programming model -->

<annotation-driven conversion-service="conversionService"
>

...
<return-value-handlers>

<beans:bean class="com.iflytek.framework.web.mvc.RequestResponseEscapeMethodProcessor"
>

<beans:property name="contentType"
>

<beans:value>
application/json;charset=UTF-8</beans:value>

</beans:property>

<beans:property name="charset"
>

<beans:value>
utf-8</beans:value>

</beans:property>

...
</beans:bean>

</return-value-handlers>

</annotation-driven>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: