首页 新闻 搜索 专区 学院

Cannot forward after response has been committed

0
悬赏园豆:50 [已解决问题] 解决于 2011-12-06 19:20
这个错误主要是由于两次跳转所引发的 但是我的代码总通过if else 判断后只跳转了一次
private void findAllFlowCardList(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String clientId = request.getParameter("clientId");
String beginDate = request.getParameter("beginDate");
String endDate = request.getParameter("endDate");
Date dBeginDate=new Date();
Date dEndDate= new Date();
int pageNo = 1;
if (request.getParameter("pageNo") != null && !"".equals(request.getParameter("pageNo"))) {
pageNo = Integer.parseInt(request.getParameter("pageNo"));
}
int pageSize = Integer.parseInt(this.getServletContext().getInitParameter("pageSize"));
try {
if (beginDate != null && !"".equals(beginDate)) {
dBeginDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(beginDate+ " 23:59:59");
}else {
dBeginDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(new SimpleDateFormat("yyyy-MM-dd").format(new Date()) + " 23:59:59");
}
if (endDate != null && !"".equals(endDate)) {
dEndDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(endDate + " 23:59:59");
}else {
dEndDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(new SimpleDateFormat("yyyy-MM-dd").format(new Date()) + " 23:59:59");
}
} catch (ParseException e) {
e.printStackTrace();
}
FlowCardManager flowcardManager = (FlowCardManager)BeanFactory.getInstance().getServiceObject("FlowCardManager");
PageModel pageModel = flowcardManager.findFlowCardList( pageSize, pageNo, clientId, dBeginDate, dEndDate);
if(pageModel.getTotlePage() != 0)
{
request.setAttribute("model", pageModel);
request.getRequestDispatcher("/flowcard/flow_card_maint.jsp").forward(request, response);
return;
}else
{
RequestDispatcher s= request.getRequestDispatcher("/flowcard/flow_card_maint.jsp");
s.forward(request, response);
return;
}

}


现在发现了引起错误的原因 我写的FlowCardServlet extends BaseServlet
在baseservlet中的service方法 中super.service(request, response); 是这行代码引起了跳转

protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
command = request.getParameter("command");
user = (User)request.getSession().getAttribute("user");
// super.service(request, response); // 会引起 Cannot forward after response has been committed 提交两次请求跳转
}

现在就很不解 为啥这行代码会引发 “Cannot forward after response has been committed” ??? 请高手指教
补充:BaseServlet extends HttpServlet
Snaker kiss的主页 Snaker kiss | 初学一级 | 园豆:155
提问于:2011-12-06 12:47
< >
分享
最佳答案
0

这要看你super.service(request, response);里的代码是怎么写的,看这里能不能帮你:

http://blog.csdn.net/me_kankan/article/details/3900275

收获园豆:50
artwl | 专家六级 |园豆:16536 | 2011-12-06 14:24
其他回答(1)
0

你的BaseServlet中,是不是还有doGet()或者doPost(),在里面是不是已经响应给客户端了?

超级无敌战 | 园豆:209 (菜鸟二级) | 2015-09-10 00:09
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册