怎么会出现 Cannot forward after response has been committed???

07-02-20 wangdj2008
下面这个是难用户的servlet:

package com.wdj;

import java.io.*;

import javax.servlet.*;

import javax.servlet.http.*;

public class CheckLogin extends HttpServlet{

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

User u=new User();

String path=null;

u.setName(request.getParameter("name"));

u.setPass(request.getParameter("pass"));

if(u.isValidate()){

path="main.jsp";

}else{

path="error.jsp";

}

request.getRequestDispatcher(path).forward(request,response);

}

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

this.doGet(request,response);

}

}

下面这个是过滤器;

package com.wdj;

import java.io.*;

import javax.servlet.*;

import javax.servlet.http.*;

public class UserFilter implements Filter{

public void init(FilterConfig congif)throws ServletException{

}

public void doFilter(ServletRequest request,ServletResponse response,FilterChain chain)throws IOException,ServletException{

String name=request.getParameter("name");

if(name!=null){

if(name.indexOf("SEX")==-1){

chain.doFilter(request,response);

}else{

System.out.println("error");

request.getRequestDispatcher("error.jsp").forward(request,response);

}

chain.doFilter(request,response);

}else{

chain.doFilter(request,response);

}

}

public void destroy(){

}

}

我一提交表单到servlet中就提示 Cannot forward after response has been committed???

请问我该怎么改呢,谢谢了,给大家拜个晚年了

猜你喜欢