• Register
0 votes

Problem :

I am trying to pass the values from the servlet to jsp page

But when I run the page I am facing below error:

Error as below :

java.lang.IllegalStateException: Cannot call sendRedirect() after the response has been committed

I tried to use the below code as well:

RequestDispatcher dd=request.getRequestDispatcher("usertaskpage.jsp");

dd.forward(request, response);

But still I got a same error.

How can I fix above error?

7 5 2
3,870 points

Please log in or register to answer this question.

1 Answer

0 votes

Solution :

It seems you have already forwarded a response in catch block with below code:

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

So,now you must not again call the :


As it is already forwarded (committed).

So what you can really do is: keep the string to assign where you need to forward a response.

    String page = "";
    try {
    } catch (Exception e) {
      page = "error.jsp";
    } finally {
      page = "usertaskpage.jsp";
RequestDispatcher dd=request.getRequestDispatcher(page);
dd.forward(request, response);


Cause of IllegalStateException exception is the java servlet is attempting to write to a response after a response has been committed. It is always better to ensure that the no content is added to a response after a forward or the redirect is done to avoid the IllegalStateException. It can be done by including the ‘return’ statement immediately next to a forward or redirect statement.

9 7 4
38,600 points

Related questions

0 votes
1 answer 415 views
Problem : I got following exception from my servlet: java.lang.illegalstateexception: response has already been committed
asked Oct 31, 2019 peterlaw 6.9k points
0 votes
1 answer 14 views
0 votes
1 answer 3 views
Does anybody know *why* that includes has to be used?
asked 4 days ago TeamScript 10.6k points
0 votes
1 answer 20 views
I am unable to spot the problem. Any help?
asked Jan 1 TeamScript 10.6k points
0 votes
1 answer 66 views
Problem : I am trying to run Java Applet and getting bellow error. java.lang.illegalstateexception: failed to create a child event loop
asked Oct 31, 2019 peterlaw 6.9k points
0 votes
1 answer 512 views
Problem : I am just a beginner in java coding. Recently i got this error and was unable to solve it. Please help me with this. exception in thread "main" java.lang.illegalstateexception: scanner closed
asked Oct 23, 2019 peterlaw 6.9k points
0 votes
1 answer 20 views
Problem: I am a na&iuml;ve to Java, Jsp, Servlet and trying to make a very small registration program with the database. But while trying to run this I am facing below errors: HTTP Status 405 - HTTP method GET is not supported by this URL type Status report message HTTP ... </welcome-file>     </welcome-file-list> </web-app> I am looking for Java expert who can help me in fixing above error.
asked Jul 29, 2020 Raphael Pacheco 4.9k points
0 votes
1 answer 19 views
I am finding difficulty to upload image in database using jsp and servlet.
asked Oct 4, 2020 Daniel Anderson 4k points
0 votes
1 answer 12 views
We need to retrieve data from database applying servlet and show it into a jsp file, however what is retrieved is only the first row of the table.
asked Sep 29, 2020 Daniel Anderson 4k points
0 votes
1 answer 14 views
We are unable to display image from the database into our jsp page and we still can&rsquo;t understand where the problem is?
asked Sep 28, 2020 Daniel Anderson 4k points