Mark Watson’s Artificial Intelligence Books and Blog

Share this post

Calling 'return' in a JSP, avoiding sendRedirect(...) problems

markwatson.com

Calling 'return' in a JSP, avoiding sendRedirect(...) problems

Mark Watson
Aug 20, 2004
Share
Share this post

Calling 'return' in a JSP, avoiding sendRedirect(...) problems

markwatson.com

A not too uncommon runtime error occurs by trying to call response.sendRedirect(...) twice on a single JSP or calling response.sendRedirect(...) while writing any output to a servlet or JSP output stream.

A trick that I use to avoid this problem is to simply 'return' immediately after calling response.sendRedirect(...). This is required because the page is not redirected instantly - it occurs after all the output to the page is written.

Simple trick, but I never see this in other people's JSP code, so I thought that it was worth mentioning it.

Share
Share this post

Calling 'return' in a JSP, avoiding sendRedirect(...) problems

markwatson.com
Comments
Top
New

No posts

Ready for more?

© 2023 Mark Watson
Privacy ∙ Terms ∙ Collection notice
Start WritingGet the app
Substack is the home for great writing