• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

IllegalStateException in JSP

 
padma patil
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have
1)one jsp page say p1.jsp which has html form and 3 submit buttons.
2)on submit it goes to p2.jsp, which depending on button name redirect to
page p3.jsp ->button1
p4.jsp ->button2
p5.jsp ->button3
I am redirecting as,
if(button.equals(new String("button1")))
response.sendRedirect("http://localhost:8080/p2.jsp");
if(button.equals(new String("button2")))
response.sendRedirect("http://localhost:8080/p2.jsp");
if(button.equals(new String("button3")))
response.sendRedirect("http://localhost:8080/p3.jsp");

when I click on buttin1 on page p1.jsp , it throws IllegalStateException if I comment all the outstream statements and response.sendRedirect statements before and after the response.sendRedirect("http://localhost:8080/p2.jsp"); statement it doesn't throws IllegalStateException .
But I need have response.sendRedirect statements if button2 or button3 are clicked.
Is there was to handle this?
Another thing is if I use <jsp:forward ......> in all if statements it works fine but when I click the browser back button from p3.jsp it give me Page expired warning and I need to refresh the page to go back to p1.jsp . With the response.sendRedirect (" ") statement refresh problem is solved but
IllegalStateException rises!!!
I realy appreciate any help in this.
thakns,
padmashree
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when I click on buttin1 on page p1.jsp , it throws IllegalStateException if I comment all the outstream statements and response.sendRedirect statements before and after the response.sendRedirect("http://localhost:8080/p2.jsp"); statement it doesn't throws IllegalStateException .

When using the sendRedirect(...) of the response, if the response is committed to the client, an IllegalStateException occurs.
You could try requestDipatcher.forward(...) method instead.
regds.
- madhav
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13058
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alternately you could specify a big buffer for the output so that it would not be flushed by the time you decide to redirect.
Bill
 
padma patil
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
Appreciated your response. I solved the problem using sendRedirect() by removing all "out" statements before and after sendRedirect();
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic