当前位置: 代码迷 >> Java Web开发 >> jsp跳转有关问题,求解决,有代码,有异常提示
  详细解决方案

jsp跳转有关问题,求解决,有代码,有异常提示

热度:6417   发布时间:2013-02-25 21:20:35.0
jsp跳转问题,求解决,有代码,有错误提示
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
super.doPost(req, resp);
Teacher t=new Teacher();
String teacherId =req.getParameter("teacherId");
t.setTeacherId(Integer.parseInt(teacherId));
String teacherName =req.getParameter("teacherName");
t.setTeacherName(teacherName);
String teacherSex =req.getParameter("teacherSex");
t.setTeacherSex(teacherSex);
String teacherAge =req.getParameter("teacherAge");
t.setTeacherAge(Integer.parseInt(teacherAge));
String teacherSchool =req.getParameter("teacherSchool");
t.setTeacherSchool(teacherSchool);
String teacherCourse =req.getParameter("teacherCourse");
t.setTeacherCouse(teacherCourse);
String teacherPhone =req.getParameter("teacherPhone");
t.setTeacherPhone(teacherPhone);
String teacherEmail =req.getParameter("teacherEmail");
System.out.println(teacherEmail);
t.setTeacherEmail(teacherEmail);
String price =req.getParameter("price");
t.setPrice(Integer.parseInt(price));
String passWord =req.getParameter("passWord");
t.setPassWord(passWord);
String teacherInfo =req.getParameter("teacherInfo");
t.setTeacherInfo(teacherInfo);
addTeacher addtea = new addTeacher();
boolean f=addtea.addTeacher(t);
System.out.println(f);
if(f){

System.out.println("插入成功!");
HttpSession session=req.getSession(true);
session.setAttribute("teacherName", teacherName);
resp.sendRedirect("AddSuccess.jsp");

return ;
}
else
resp.sendRedirect("login.jsp");
return ;
}
 

}
2012-5-14 16:54:53 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet addteacher threw exception
java.lang.IllegalStateException: Cannot create a session after the response has been committed
at org.apache.catalina.connector.Request.doGetSession(Request.java:2390)
at org.apache.catalina.connector.Request.getSession(Request.java:2110)
at org.apache.catalina.connector.RequestFacade.getSession(RequestFacade.java:833)
at com.service.AdminaddTeacherServlet.doPost(AdminaddTeacherServlet.java:46)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:619)

------解决方案--------------------------------------------------------
java.lang.IllegalStateException: Cannot create a session after the response has been committed

把这句话放到doPost()最前面去:
HttpSession session=req.getSession(true);

一开始就要把session准备好。

------解决方案--------------------------------------------------------
  相关解决方案
本站暂不开放注册!
内测阶段只得通过邀请码进行注册!
 
  • 最近登录:Tue Mar 19 06:18:05 CST 2019
  • 最近登录:Tue Mar 19 06:18:05 CST 2019
  • 最近登录:Tue Mar 19 06:18:05 CST 2019
  • 最近登录:Tue Mar 19 06:18:05 CST 2019
  • 最近登录:Tue Mar 19 06:18:05 CST 2019