• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

IllegalStateException in JSP

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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();
 
It's exactly the same and completely different as this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic