• 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

sendRedirect(url) problem in jsp

 
Ranch Hand
Posts: 57
Netbeans IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi friends,


I am new to JSP I am using response.sendRedirect() in my jsp when a condition becomes true or false it will go to success.jsp. While executing this I am getting "IllgalStateException and the response is not forwarding to "success.jsp". why this is occuring i need your help .

code snipet is:

<%
if(rs.next()==true)
{
response.sendRedirect("../success.jsp?work=add");
}
else
{
response.sendRedirect("../success.jsp?work=addFailed");
}
%>


I am getting java.lang.IllegalStateException .

Please help me to resolve this exception..
 
Ranch Hand
Posts: 174
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First.. use code tags

Second.. Search First

And Final, you can find your solution here
 
mike mimmis
Ranch Hand
Posts: 57
Netbeans IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ya i tried both

1. return;

2. <% --------
 
Chinna Eranna
Ranch Hand
Posts: 174
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What do you mean by I tried both ?
 
mike mimmis
Ranch Hand
Posts: 57
Netbeans IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Chinna Eranna wrote:What do you mean by I tried both ?



i mean after writing response.sendRedirect("../success.jsp?work=add");

i add a line i.e return; I am getting same exception thats it.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Step 1 is to refactor your JSP to contain no Java code. The problems you are having are just one of the many reasons that this practice has been discredited for almost 10 years now. Time to update your knowledge.
 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you already done output on this page? If so then sending a redirect will often result in an Illegal State Exception.

Any redirects should be done BEFORE outputting any text. That way you don't have to cancel the stuff you have written already.
 
mike mimmis
Ranch Hand
Posts: 57
Netbeans IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stefan Evans wrote:Have you already done output on this page? If so then sending a redirect will often result in an Illegal State Exception.

Any redirects should be done BEFORE outputting any text. That way you don't have to cancel the stuff you have written already.



hi stefen how it is achievable?
 
mike mimmis
Ranch Hand
Posts: 57
Netbeans IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:Step 1 is to refactor your JSP to contain no Java code. The problems you are having are just one of the many reasons that this practice has been discredited for almost 10 years now. Time to update your knowledge.




hi sir,

I am new to jsp. I knew a little about jsp so i cant understand what you are saying can you give me a example
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are new to JSP, it is important to start off on the right foot.

And that means NO JAVA CODE in the JSP. None. Nada. Zero.

That's a practice from last decade before JSP 2 and is now discredited.

Get yourself a modern JSP reference that concentrates on the JSTL (JSP Standard Tag Library) and the EL (Expression Language).

That vast majority of problems in JSP reported in this forum are due to people insisting on doing it wrong when doing it right is so much easier.
 
mike mimmis
Ranch Hand
Posts: 57
Netbeans IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:If you are new to JSP, it is important to start off on the right foot.

And that means NO JAVA CODE in the JSP. None. Nada. Zero.

That's a practice from last decade before JSP 2 and is now discredited.

Get yourself a modern JSP reference that concentrates on the JSTL (JSP Standard Tag Library) and the EL (Expression Language).

That vast majority of problems in JSP reported in this forum are due to people insisting on doing it wrong when doing it right is so much easier.




can you suggest me any book or blog to know more..
 
Chinna Eranna
Ranch Hand
Posts: 174
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Head First Servlets And JSP is a good book.

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for book
 
mike mimmis
Ranch Hand
Posts: 57
Netbeans IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you very much for sharing book name ....
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! 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