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.