我正在尝试编写一个以xml格式返回数据的servlet。我正在尝试为该特定请求生成唯一ID,并且当我尝试在XML请求中添加uuid
时,我总是在浏览器上收到以下错误 -
This page contains the following errors:
error on line 2 at column 14: AttValue: " or ' expected
Below is a rendering of the page up to the first error.
这就是我的代码的样子 -
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
final String uuid = UUID.randomUUID().toString().replaceAll("-", "");
System.out.println("uuid = " + uuid);
response.setContentType("application/xml");
PrintWriter writer = response.getWriter();
writer.println("<?xml version=\"1.0\"?>");
writer.println("<request uuid = "+uuid+">");
writer.println("<app hash = \"abc\"/>");
writer.println("<app hash = \"def\"/>");
writer.println("</request>");
writer.flush();
}
我的上述代码有问题吗?谁能指导我,我做错了什么?
感谢您的帮助!!
答案 0 :(得分:3)
我猜你应该把你的UUID放在引号之下:
writer.println("<request uuid = \""+uuid+"\">");
请注意额外的
围绕uuid。\“
答案 1 :(得分:2)
您忘记了属性值周围的"
,更改:
writer.println("<request uuid = "+uuid+">");
到
writer.println("<request uuid = \""+uuid+"\">");
它应该有用。