求助: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
请问各位大哥这是怎么回事啊!
[解决办法]
return mapping.findForward( "target ");
是因为没有引号吗?
[解决办法]
虽然在代码里面没有看到response的提交的代码,但是根据提示应该是你在什么代码里面对response进行了发送或者flush之类的操作。你可以检查一下。
[解决办法]
路径不会有问题吧,
你的提交的页面是在web目录下还是在跟目录下
[解决办法]
我用SERVLET时也有这种错误,但是还不知道具体原因
[解决办法]
同意fastmask,贴出来的代码似乎没问题,可能你在filter或listener里用了response.redirect(...),由于重复提交response,所以出现这样的错误!
[解决办法]
在struts的配置文件中你的action怎么没有对应的ActionForm,难道没有报错吗
[解决办法]
[解决办法]
1、return时没有加引号 2、struts-config.xml中并没有配置target
[解决办法]