0

与我之前遇到的类似问题,但是这次之前的解决方法不起作用。与 相关的代码抛出如下所示的错误在此处输入图像描述

如果图像无法加载这里的代码

    LongLivedCookie c =
    new LongLivedCookie("accessCount",
                      String.valueOf(count+1));
    response.addCookie(c);
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    String title = "Access Count Servlet";
    String docType =
      "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 " +
      "Transitional//EN\">\n";
     out.println(docType +
            "<HTML>\n" +
            "<HEAD><TITLE>" + title + "</TITLE></HEAD>\n" +
            "<BODY BGCOLOR=\"#FDF5E6\">\n" +
            "<CENTER>\n" +
            "<H1>" + title + "</H1>\n" +
            "<H2>This is visit number " +
            count + " by this browser.</H2>\n" +
            "<form id="form" name="form" method="post" action='Question_3.jsp'           

            padding="10" >" +
             "<button type="submit">Submit</button> " +
            "</CENTER></BODY></HTML>");
      }
     }
4

2 回答 2

0

Java字符串以引号开头和结尾,如果您想在字符串中使用引号,那么您应该使用 \ 对它们进行转义,例如“id=\"xyz\""

于 2013-04-07T13:47:14.933 回答
0

代码应该转义字符串文字中的双引号。

 out.println(docType +
            "<HTML>\n" +
            "<HEAD><TITLE>" + title + "</TITLE></HEAD>\n" +
            "<BODY BGCOLOR=\"#FDF5E6\">\n" +
            "<CENTER>\n" +
            "<H1>" + title + "</H1>\n" +
            "<H2>This is visit number " +
            count + " by this browser.</H2>\n" +
            "<form id=\"form\" name=\"form\" method=\"post\" action='Question_3.jsp'           
            padding=\"10\" >" +
             "<button type=\"submit\">Submit</button> " +
            "</CENTER></BODY></HTML>");
      }
于 2013-04-07T13:48:50.423 回答