各位,这个异常该如何解决呢?

qkmadcat 2004-10-06 03:44:54
java.lang.IllegalStateException: Cannot forward after response has been committed
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:367)

at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:355)

at org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1069)

at org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:455)

at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:279)

at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)

at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)

at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243)

at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)

at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)

at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)

at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:190)

at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)

at org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:246)

at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)

at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)

at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)

at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2347)

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)

at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)

at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)

at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)

at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:170)

at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)

at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)

at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)

at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)

at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)

at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)

at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)

at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:1027)

at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1125)

at java.lang.Thread.run(Thread.java:534)
...全文
50 点赞 收藏 4
写回复
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
ladofwind 2004-10-07
forward前面不能有太多的东西,不然就出错
回复
qkmadcat 2004-10-06
我用debug跟了一下,发现是在最后return时抛出的异常
回复
qkmadcat 2004-10-06
然后在action中调用业务层,当出错时就用showMessagePage()打印一个页面,代码如下:
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {

Operator operator = (Operator) form;
ErrorMessage errorMessage = new ErrorMessage();
//从web层获得用户名和口令
//String userId = new String(operator.getUserId().trim().getBytes("ISO8859-1"),"gb2312");
String userId = this.getStr(operator.getUserId().trim());
String password = operator.getPassword().trim();
//声明错误集对象
if (userId.equals("")){
errorMessage.showMessagePage(response,"错误","请填入登陆用户名!");
}
else{
boolean validated = false;
try {
Logon logon = new Logon();
validated = logon.isValidateUserID$Password(userId, password);
if (validated == true) {
//一切正常就保存用户信息并转向成功的页面
HttpSession session = request.getSession();
session.setAttribute("userInfoForm", form);
return mapping.findForward("success");
}
logon.destroySession();
}
catch (Throwable e) {
//处理可能出现的错误
errorMessage.showMessagePage(response,"错误!","用户名与密码不匹配,请返回重新输入!");
}
}
return new ActionForward(mapping.getInput());
}
回复
qkmadcat 2004-10-06
我在业务层判断用户名和密码不正确时我加了一个error类,就是打印出一个出错页面,代码如下:
package com.madcat.logon.action;

import java.io.PrintWriter;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class ErrorMessage {

public ErrorMessage() {
}

protected void showMessagePage(HttpServletResponse response, String title, String message) throws IOException
{
response.setContentType("text/html; charset=GB2312");
PrintWriter out = new PrintWriter(response.getOutputStream()); // 从响应中得到一个输出的对象
out.println("<html>");
out.println("<head><title>" + title + "</title>");
out.println("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=" + response.getCharacterEncoding() + "\"></head>");
out.println("<body>");
out.println("<p>" + message);
out.println("<p><a href = javascript:history.go(-1)>return</a>");
out.println("</body></html>");
out.close();

}

}
回复
发动态
发帖子
Web 开发
创建于2007-09-28

7.9w+

社区成员

Java Web 开发
申请成为版主
社区公告
暂无公告