• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

IllegalStateException in JSP  RSS feed

 
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
 
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
 
Author and all-around good cowpoke
Posts: 13078
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();
 
No. No. No. No. Changed my mind. Wanna come down. To see this tiny ad:
ScroogeXHTML - small and flexible RTF to HTML converter library
https://coderanch.com/t/710903/ScroogeXHTML-RTF-HTML-XHTML-converter
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!