我在 jsp 应用程序中的重定向存在一些问题。
我的重定向方法是这样的:
public static void redirectUrl(String url,HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException
{
request.getSession().getServletContext().getRequestDispatcher("/" + url).forward(request,response);
}
当我在 localhost 上启动应用程序时,一切正常,但是当我将它部署到服务器上时,它会因以下异常而崩溃:
Servlet error
java.lang.IllegalStateException: Response has already been committed
at com.evermind[Oracle Application Server Containers for J2EE 10g (10.1.2.3.0)].server.http.EvermindHttpServletResponse.resetBuffer(EvermindHttpServletResponse.java:1933)
at com.evermind[Oracle Application Server Containers for J2EE 10g (10.1.2.3.0)].server.http.ServletRequestDispatcher.forward(ServletRequestDispatcher.java:221)
at app.framework.request.Controller.doPost(Controller.java:50)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at com.evermind[Oracle Application Server Containers for J2EE 10g (10.1.2.3.0)].server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:835)
at com.evermind[Oracle Application Server Containers for J2EE 10g (10.1.2.3.0)].server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:341)
at com.evermind[Oracle Application Server Containers for J2EE 10g (10.1.2.3.0)].server.http.ServletRequestDispatcher.forward(ServletRequestDispatcher.java:230)
at com.evermind[Oracle Application Server Containers for J2EE 10g (10.1.2.3.0)].server.http.GetParametersRequestDispatcher.forward(GetParametersRequestDispatcher.java:257)
我在每次重定向调用之后都放了 return 语句,但它不起作用。
有人能告诉我为什么吗?
提前致谢。