struts2 用标签 取值 json 含有转义字符的解决方法

java web 开发时,基于 struts2 框架,遇 html 标签取值字符串或者数字,用以下方法没有问题,但遇到取得的结果是 json 就会被 struts2 编码,得不到正确信息,中间会被加上很多转义符号。

// 非 json 信息,显示结果正常


遇到 json 结果时,就要使用 escape='false' 属性,关闭转义功能,以确保在取得 json 时得到正确(原始)信息。

struts 2.3 版本 property 属性
escape='false'/>

struts 2.5 版本 property 属性

Name

Required

Default

Evaluated

Type

Description

default false   false String The default value to be used if value attribute is null
escapeCsv false false false Boolean Whether to escape CSV (useful to escape a value for a column)
escapeHtml false true false Boolean Whether to escape HTML
escapeJavaScript false false false Boolean Whether to escape Javascript
escapeXml false false false Boolean Whether to escape XML
value false false Object Value to be displayed

escapeHtml='false'/>


下图中是关闭转义和不关闭转义得到的两种信息,下半部分被转义后的信息完全不能使用。

struts2 用标签 取值 json 含有转义字符的解决方法_第1张图片


参考:https://struts.apache.org/docs/property.html

你可能感兴趣的:(所有,struts2,Web前端)