-1

我正在尝试编写一个以 xml 格式返回数据的 servlet。我正在尝试为该特定请求生成一个唯一 ID,一旦我尝试将其添加到uuidXML 请求中,我总是在浏览器上收到以下错误-

   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();
}

我上面的代码有什么问题吗?谁能指导我我做错了什么?

谢谢您的帮助!!

4

2 回答 2

3

我想你应该把你的 UUID 放在引号下:

writer.println("<request uuid = \""+uuid+"\">");

注意额外的

\"

围绕uuid。

于 2013-06-30T22:45:13.677 回答
2

你忘记了"周围的属性值,改变:

 writer.println("<request uuid = "+uuid+">");

 writer.println("<request uuid = \""+uuid+"\">");

它应该可以工作。

于 2013-06-30T22:45:04.033 回答