• 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

 
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
am getting IllegalStateException when iam using response.sendRedirect.I have not
used response.flushBuffer() in that page. And i have caught the Exception also. I
have tried and got 2 solutions also
1) response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
response.setHeader("Location","/sivashakthi/general/editError.jsp?path="+request.getRequestURI()+"&message="+message);
generally this is working fine but when iam using in place of sendRedirect
where iam getting illegal it is not working nothing is making difference
2) changed the buffer size=12
its working fine but my superior needs sol by coding it seems.
for coding i have to pass through url but sendRedirect is not working

any body plz help
[ September 03, 2005: Message edited by: sai prasanna ]
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Neither response.sendRedirect nor requestDispatcher.forward will stop the execution of your page on their own.

For this reason, you should either branch your code in such a way that no code is reached after calling either of them or put a return statement just afer makeing the call.


If that wasn't the problem, post your code so we can take a look.
[ September 03, 2005: Message edited by: Ben Souther ]
 
sai prasanna
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ben Souther:
Neither response.sendRedirect nor requestDispatcher.forward will stop the execution of your page on their own.

For this reason, you should either branch your code in such a way that no code is reached after calling either of them or put a return statement just afer makeing the call.


If that wasn't the problem, post your code so we can take a look.

[ September 03, 2005: Message edited by: Ben Souther ]

 
sai prasanna
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by sai prasanna:

If that wasn't the problem, post your code so we can take a look.

[ September 03, 2005: Message edited by: Ben Souther ]<hr></blockquote>[/QB]




Thanks Ben
I even tried with this code and iam getting IllegalStateException. My code is

i used jsp aram

<% if("Update".equalsIgnoreCase(action)){
message = "Vehicle/Insurance Taxes Updation ";
if(vehicle!=null && insuranceTax!=null &&
vehicle.getVehicleNo()!=null &&
vb.upDateVehicle(vehicle) &&
itb.updateInsuranceTaxes(insuranceTax)){
flag=false;
try{
response.sendRedirect("/sivashakthi/transport/edit/vehicleMasterEdit.jsp?action="+action+"&count=1");
}catch(Exception ise){
ise.printStackTrace();
}
}else{
response.sendRedirect("/sivashakthi/general/updateError.jsp?path="+request.getRequestURI()+"&message="+message);
}
}else if("Delete".equalsIgnoreCase(action)){
message = "Vehicle/Insurance Taxes Deletion ";
if(vehicle!=null && insuranceTax!=null && vehicle.getVehicleNo()!=null && vb.deleteVehicle(vehicle) && itb.deleteInsurance(insuranceTax)){
flag=false;
try{
response.sendRedirect("/sivashakthi/transport/edit/vehicleMasterEdit.jsp?count=1");

}catch(IllegalStateException ise){
ise.printStackTrace();
}
}else{
try{
//if(!response.isCommitted())
//System.out.println("un committed");
//else
//System.out.println("committed");

//or

//response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
//response.setHeader("Location","/sivashakthi/general/editError.jsp?path="+request.getRequestURI()+"&message="+message");

if(flag){
response.sendRedirect("/sivashakthi/general/editError.jsp?path="+request.getRequestURI()+"&message="+message);
return;
}

}catch(Exception e){
e.printStackTrace();
}
}
}
}else{
response.sendRedirect("/sivashakthi/general/sorry.jsp");
}
%>
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's tricky to use redirect within a JSP, because the page generates output, after which a redirect is no loger possible. It would be a better design to determine which action/path to take somewhere in a servlet or Java class, and then to do a forward or redirect from there to the appropriate JSP page.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sai,
Make it very simple for yourself.
After every call to response.sendRedirect, add a return statement.

If you must test the output stream after a redirect, make sure to add a return statement before closing your scriptlet tag. Otherwise the JSP compiler will may add println statements that will cause the IllegalStateException.

JSPs are best used for formatting your output.
Servlets are better for handling control flow.
 
Remember to always leap before you look. But always take the time to smell the tiny ads:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic