2013-04-07 67 views
0

类似的问题,我之前有一个之前的工作,但这次没有工作。关心抛出下面enter image description hereServlet html没有打印表格

显示,如果图像不会加载这里的错误代码的代码

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

我无法看到任何东西的图片... :) – 2013-04-07 13:45:42

+0

对不起,我在代码中添加了现在 – H65 2013-04-07 13:46:42

+0

HTML不属于servlet的。学习如何使用JSP进行HTML:http://stackoverflow.com/tags/servlets/info – BalusC 2013-04-08 21:02:45

回答

0

Java字符串开始,以引号结束,如果你想在字符串中使用引号作为你的情况下,你应该使用\来转义它们,例如“id = \”xyz \“”

+0

使用转义我有他行为这个“”但它仍然会抛出错误 – H65 2013-04-07 13:55:03

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>"); 
     } 
+0

这个作品,谢谢! – H65 2013-04-07 13:57:19

+0

@ Heafy65很高兴我能帮忙。 – 2013-04-07 13:59:01