当前位置: 代码迷 >> J2EE >> :Cannot forward after response has been committed
  详细解决方案

:Cannot forward after response has been committed

热度:581   发布时间:2016-04-22 02:40:54.0
求助:Cannot forward after response has been committed
login_Faild.jsp:
<%@   page   contentType= "text/html;charset=gb2312 "%>
<%@   taglib   uri= "/tags/struts-html "   prefix= "html "   %>
<html>
    <head>
        <title> </title>
        <meta   http-equiv= "Refresh "   content= "3;url=/web/login.html ">  
    </head>
   
    <body>
    <b> <html:errors/> </b> <br/>
    </body>
</html>

-------------------------------------------
UserAction.java:
public   ActionForward   login(ActionMapping   mapping,   ActionForm   form,
HttpServletRequest   request,   HttpServletResponse   response)  
{
String   username   =   request.getParameter( "username ");
String   pwd   =   request.getParameter( "password ");
ActionErrors   errors   =   new   ActionErrors();
String   target   =   "index ";

if(username   ==   null   ||   username.trim().length()   ==0   ||  
pwd   ==   null   ||   pwd.trim().length()   ==   0)
{
errors.add(ActionErrors.GLOBAL_ERROR,   new   ActionError( "Username   and   password   can   not   blank. "));
target   =   "loginFailed ";
}  
else  
{
User   user   =   new   User();
user.setPwd(pwd);
user.setUsername(username);
UserService   service   =   new   UserService();
try  
{
service.login(user);
HttpSession   session   =   request.getSession(true);
session.setAttribute( "UserSession ",   user);
}
catch(AuthenticationException   ex)  
{
errors.add(ActionErrors.GLOBAL_ERROR,   new   ActionError( "Username   or   password   is   invalid. "));
target   =   "loginFailed ";
}
}

 
if(!errors.isEmpty())
saveErrors(request,   errors);

return   mapping.findForward(target);
}
---------------------
struts-config.xml
        <action
            parameter= "method "
            path= "/userAction "
            scope= "request "
            type= "com.cogentsystems.ib.presentation.action.UserAction ">
            <forward   name= "loginpage "   path= "/login.html "   />
            <forward   name= "index "   path= "/index_page.html "   />
            <forward   name= "loginFailed "   path= "/login_Failed.jsp "   />
        </action>

现在登陆页一提交就抱错:
java.lang.IllegalStateException:   Cannot   forward   after   response   has   been   committed
我使用的是TOMCAT   5.0
  相关解决方案