【发布时间】:2015-11-29 20:06:10
【问题描述】:
从数据库和编组到字符串的视图
String xml = XMLUtils.marshallToString(list);
sre.getServletRequest().setAttribute("LIST", xml);
和代码JS
var regObject = '${requestScope.LIST}';
..... 在浏览器中打开时。查看源代码我有错误 Unexpected token ILLEGAL。
var regObject = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>//Unexpected token ILLEGAL
<items>
<item>
<id>ID</id>
<productName>PrdName</productName>
<productLink>LINK</productLink>
<productImage>IMG</productImage>
</item>
</items>';
JAXBContext jaxb = JAXBContext.newInstance(List.class);
Marshaller mar = jaxb.createMarshaller();
mar.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
mar.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
StringWriter sw = new StringWriter();
mar.marshal(items, sw);
return sw.toString();
有人知道如何解决这个问题吗?
【问题讨论】:
标签: javascript java xml session