我正在尝试将请求从Servlet重定向到JSP。我的要求是threadpoolexecutor。这是我的servlet代码。我正在编写doPost方法以节省时间。
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
String action=request.getParameter("action");
HttpSession session=request.getSession();
if(action==null){
String user=request.getParameter("username");
String pass=request.getParameter("password");
boolean remember=request.getParameter("remember")!=null;
ConnectionTest cn=new ConnectionTest();
conn=cn.getConn();
try{
psmt=conn.prepareStatement(qry);
psmt.setString(1, user);
psmt.setString(2, pass);
rs=psmt.executeQuery();
if(rs.next()){
session.setAttribute("username", user);
// response.sendRedirect("/main.jsp");
if(remember){
Cookie cku=new Cookie("username", user);
cku.setMaxAge(3600);
response.addCookie(cku);
Cookie ckp=new Cookie("password", pass);
ckp.setMaxAge(3600);
response.addCookie(ckp);
JOptionPane.showMessageDialog(null, user+" : "+pass);
}
request.getRequestDispatcher("main.jsp").forward(request, response);
//response.sendRedirect("/main.jsp");
}
else{
session.setAttribute("error", error);
request.getRequestDispatcher("login.jsp").forward(request, response);
//response.sendRedirect("/login.jsp");
}
}
catch(Exception e){
JOptionPane.showMessageDialog(null, e);
System.out.println(e);
}
}
}
以下是我遇到的错误
java.lang.IllegalStateException:在提交响应后无法转发