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 ]
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 ]
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
Joined: May 02, 2005
Posts: 167
posted
0
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
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.
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.