我正在使用 JSP 和 Servlet(IDE:Eclipse,数据库:Oracle10)开发 Web 应用程序。我正在使用 jqGrid 以表格格式显示记录。
我正在使用datatype: "xml"
对于 jqgrid
.
我在数据库中有一个字段用于存储 address
该字段包含特殊字符,如 ,
;
&
等等。如果Address
中的任何一个数据库包含&
然后jqgrid
正在给我留言 response 200 ok, type: parsererror
并且网格中没有显示任何数据,如果我删除 &
来自数据库,那么它不会向我显示此消息并在网格中显示数据。
{name:'ADDRESS',index:'ADDRESS', width:80,sortable:true,editable:true}
所以我的问题是我应该如何发送数据,其中包含 &
更新1:
我知道有些字符是 XML reserved characters
喜欢 &
<
和>
,但在这种情况下我必须写 loop
用于检查服务器端的地址,如果该地址包含此保留字符,那么我必须将它们写为 hexadecimal
,那么有没有更好的方法呢?
更新2: 我正在使用 Servlet。 以下是我的代码片段。
out.print("<cell>" +ADDRESS +"A&BC"+"</cell>");//will show parsererror
out.print("<cell>" +ADDRESS +"A"+"</cell>");//will not show error, and data is diplayed
提前致谢...
最佳答案
要放置具有 XML 保留字符的信息,您必须使用 XML 保留字符 <![CDATA[...]]>
(例如,请参阅 here 和 here)构造以生成正确的 XML 数据。
在客户端,您还应该使用 autoencode: true
另外还有 jqGrid 选项。
关于java - jqgrid解析器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15061769/