日期:2014-05-18  浏览次数:20791 次

response.sendRedirect的问题!
我有:

public   class   LoginAction   extends   Action  
{

public   ActionForward   execute(ActionMapping   mapping,   ActionForm   form,   HttpServletRequest   request,   HttpServletResponse   response)

LoginForm   lf=(LoginForm)form;
String   act=mapping.getParameter();
if(lf.getUsername().equals( " "))
{

response.sendRedirect( "err.jsp ");
}

}
没有写全, 当if条件成立之后(我打出过),response.sendRedirect有错误,err.jsp存在.
错误如下:
The   server   encountered   an   internal   error   ()   that   prevented   it   from   fulfilling   this   request.

java.lang.IllegalStateException
org.apache.coyote.tomcat5.CoyoteResponseFacade.sendRedirect(CoyoteResponseFacade.java:399)
org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:385)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:231)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:415)
javax.servlet.http.HttpServlet.service(HttpServlet.java:763)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
请指教!

------解决方案--------------------
response.sendRedirect();并不马上就执行重定向,而是继续执行该命令后面的代码

sendRedirect之后马上return即可
------解决方案--------------------
最好在最后sendredirect,前面可以判断选择参数。
我的异常网推荐解决方案:The server encountered an internal error () that prevented it from fulfilling this request.,http://www.aiyiweb.com/java-web/317.html