| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1273 人关注过本帖
标题:求助:Cannot forward after response has been committed
只看楼主 加入收藏
那溡婲開
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2007-4-4
收藏
 问题点数:0 回复次数:4 
求助:Cannot forward after response has been committed

在做登陆的时候出现这个错误:Cannot forward after response has been committed

请高手指教

代码如下:

package cn.com.blog.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import cn.com.blog.model.User;
import cn.com.blog.service.IUserService;
import cn.com.blog.service.ServiceFactory;
import cn.com.blog.util1.SessionUtil;

public class LoginAction extends HttpServlet {

protected static Log log = LogFactory.getLog("processLog");
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
try{
log.debug("接受用户请求!");

String username=request.getParameter("name");
String password=request.getParameter("password");
//把数据存储到持久化中对象
User user = new User();
user.setName(username);
user.setPassword(password);
//调用Service层接口的处理类处理
IUserService userService=ServiceFactory.getUserService();
//获得Session对象
HttpSession session=request.getSession();
//获得输出流对应的writer对象
PrintWriter out = response.getWriter();
if(userService.login(user)){
User u = userService.getUser(user.getName());
SessionUtil.saveUser( request, u );

this.getServletContext().getRequestDispatcher("/HomePageAction").forward(request,response);


}else{

out.println("<center><font color='red'>用户名或密码错误!</font><a href='#' onclick='history.back();'>返回</a></center>");
}

}
catch(Exception e){
e.printStackTrace();
log.debug("用户请求处理出错!");
request.setAttribute("errMsg","登录出错!");
this.getServletContext().getRequestDispatcher("/Blog/myerror.jsp").forward(request,response);
return;
}

}


public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request,response);
}

}

搜索更多相关主题的帖子: response Cannot committed forward 
2007-04-04 16:05
那溡婲開
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2007-4-4
收藏
得分:0 
回复:(那溡婲開)求助:Cannot forward after respo...
在线等候!急!!!!
2007-04-04 16:13
风月_无边
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:60
帖 子:2960
专家分:652
注 册:2007-1-19
收藏
得分:0 
Cannot forward after response has been committed
这是怎么回事?

我的网站 http://www.
2007-04-05 21:26
时空之蕊
Rank: 2
等 级:新手上路
威 望:3
帖 子:691
专家分:0
注 册:2004-10-31
收藏
得分:0 
在forward前调用了response。flush,这个是不正确的

我渴望掌控时空的核心——用最先进的技术,打造无比美丽的世界!
2007-04-05 22:45
亮剑
Rank: 1
等 级:新手上路
帖 子:148
专家分:0
注 册:2006-10-18
收藏
得分:0 
用include试试看
2007-04-06 20:25
快速回复:求助:Cannot forward after response has been committed
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.025749 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved