Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Tricky: Servlet cannot forward after response has been committed

843841Jun 28 2005 — edited Jul 23 2005
This might be a little tricky.

I have an abstract servlet class I use as a front controller. It kind of looks like this:
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		this.doPreprocess(request, response);
	}
	
	public final void doPreprocess(HttpServletRequest request, HttpServletResponse response) 
			throws ServletException, IOException {		
		
		HttpSession session = request.getSession();
						
		String labelId = request.getParameter("labelId");
		Integer lblId = null;
		
		if (labelId != null) lblId = new Integer(labelId);
		LabelData ld = new LabelData(lblId);
		request.setAttribute("allLabels", ld.getAllLabels());
		
		if (ld.getFilteredLabels() != null) {
			request.setAttribute("filteredLabels", ld.getFilteredLabels());
		}
		
		this.processRequest(request, response);
	}
	
	// Abstract method to be defined by extending class.
	public abstract void processRequest(HttpServletRequest request, HttpServletResponse response) 
			throws ServletException, IOException;
I then extend it with this:
public class Home extends BaseController {
	
	public static final long serialVersionUID = 10; 

	public void processRequest(HttpServletRequest request, HttpServletResponse response) 
			throws ServletException, IOException {
		
		RequestDispatcher d = request.getRequestDispatcher("/home.jsp");
		d.forward(request, response);		
	}
}
The problem is, when I run it I get:
java.lang.IllegalStateException: Cannot forward after response has been committed
Does anyone know why? I am not even forwarding control to another servlet. I am simply extending the class.

Thanks.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 20 2005
Added on Jun 28 2005
12 comments
25,085 views