类似的问题,我之前的工作,但这次的工作不起作用。与此相关的代码是抛出
下面显示的错误如果图像不在这里加载代码
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>");
}
}
答案 0 :(得分:0)
Java字符串以引号开头和结尾,如果要在字符串中使用引号,则应使用\来转义它们,例如“id = \”xyz \“”
答案 1 :(得分: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>");
}