我已经在服务和发布方法中编写了以下代码
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter p = response.getWriter();
p.println("<html><body>");
p.println("<form action = roomlog2 method = post>");
p.println("<input type = submit value = back>");
p.println("</form>");
p.println("</body></html>");
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.sendRedirect("homepage.html");
}
但是当我执行代码并单击后退按钮时,post方法没有执行。我得到以下异常
java.lang.NumberFormatException: null
为什么post方法不重定向到"homepage.html"?为什么我会得到例外?请有人告诉我这个错误。
只需移除service()
方法的实现,或者让它调用super.service()
。doPost()
就是这样被调用的。目前你根本不叫它。