0

This is the code in doPost:

try {
    switch (request.getParameter("action")){
        case "delete":
            request.setAttribute("message", "Deleting...");
            break;
        case "update":
            request.setAttribute("message", "Updating...");
            break;
        case "new":
            response.sendRedirect("createNew.jsp");     
            break;
        default:
            super.doPost(request, response);
            break;
    }
} finally {
    request.getRequestDispatcher("backHome.jsp").forward(request, response);
    out.close();
}

The problem is in the finally I'm getting this exception when the case is 'new': java.lang.IllegalStateException:

1 Answers1

1

In case of "new" you are doing response.sendRedirect("createNew.jsp");. At this point response stream is written.

In finally you are doing request.getRequestDispatcher("backHome.jsp").forward(request, response);. It is forwarding to another url.

But since on response already some content is written another forward cannot happen. This throw java.lang.IllegalStateException.

Bhushan Bhangale
  • 10,921
  • 5
  • 43
  • 71