我是 Java EE 领域的初学者。我一直在尝试按照http://come2niks.com/?p=1589此处提供的指南使用 Servlets 和 JSP 创建一个简单的登录系统。这就是我的 doPost() 的样子。
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
PrintWriter out = response.getWriter();
processRequest(request, response);
try
{
System.out.println("In the Login Servlet");
LoginBean user = new LoginBean();
user.setUserName(request.getParameter("username"));
user.setPassword(request.getParameter("pass"));
LoginDAO db = new LoginDAO();
user = db.login(user);
System.err.println("I am Back !");
if(user.isValid())
{
System.err.println("VALIDED.. ReDirecting..");
System.err.println("Getting Session");
HttpSession session = request.getSession(true);
System.err.println("Got Session");
session.setAttribute("currentSessionUser",user);
System.err.println("Attribute Set");
response.sendRedirect("Login_Success.jsp");
}else
{
System.err.println(" NOT VALIDED.. ReDirecting..");
response.sendRedirect("Login_Failed.jsp");
out.println(" NOT VALIDED.. ReDirecting..");
}
} catch (Throwable exc)
{
System.out.println(exc);
}
}
我添加了一些 System.err 以获取有关代码流的更多信息。
这就是我的玻璃鱼说的
INFO: In the Login Servlet
INFO: Driver loaded!
INFO: Database connected!
INFO: Welcome Ramesh
SEVERE: I am Back !
SEVERE: VALIDED.. ReDirecting..
SEVERE: Getting Session
SEVERE: Got Session
SEVERE: Attribute Set
INFO: java.lang.IllegalStateException
at org.apache.catalina.connector.ResponseFacade.sendRedirect(ResponseFacade.java:524)
at groovers.LoginServlet.doPost(LoginServlet.java:100)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:688)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:770)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1550)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
at java.lang.Thread.run(Thread.java:722)
请帮我解决这个问题。