a code is better than an explanation :
in my servlet :
...
this.getServletContext
.getRequestDispatcher("..../foo.jsp")
.forward(request, response); // (1)
// (2)
this.getServletContext
.getRequestDispatcher("..../bar.jsp")
.forward(request, response); // (3)
...
if i call the url related to this servlet, I get the following error :
"Cannot forward after response has been committed"
because (1) set the jsp to use, (3) try to set another jsp. (notice : I know it is bad example but this is to provide a minimal code).
What I want is to "stop" the servlet to process any further instructions after (1) :
- (1) is set
- (2) writing something to say I want (1) to be used
- (3) not to be read
How can I do that ?
A simple solution would be to have something like this:
From the Java docs:
Or, if as you say above, the first block of code is dependent on the user having limited permissions: