Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

sendRedirect(url) problem in jsp

 
mike mimmis
Ranch Hand
Posts: 57
Java MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • 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..
 
Chinna Eranna
Ranch Hand
Posts: 174
Java
  • Mark post as helpful
  • send pies
  • 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
Java MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
What do you mean by I tried both ?
 
mike mimmis
Ranch Hand
Posts: 57
Java MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • 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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64683
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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.
 
Stefan Evans
Bartender
Posts: 1687
10
  • Mark post as helpful
  • send pies
  • 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
Java MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • 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
Java MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Pie
Posts: 64683
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
Java MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Head First Servlets And JSP is a good book.

 
Raghu Chary
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for book
 
mike mimmis
Ranch Hand
Posts: 57
Java MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you very much for sharing book name ....
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic