I\'ve got a JSP page, which calls a function and checks its return value. If the return value is not null, the JSP page goes on to use it. If the return value IS null, I wan
Regardless of how to terminate processing of a JSP early, I would suggest handling flow control in a servlet prior to handling the display, and switch to an appropriate JSP depending on the outcome of the function call.
I tend to use JSPs purely for displaying the contents of a bean (or more than one), and all logic is contained within the invoking servlet. By doing this you get a much cleaner separation of concerns between your components, and a more easily comprehensible and debuggable system.
You may use JSTL tag:
<c:if test="condition"> bodytext </c:if>
Which is better than <% if(condition) { %> bodytext <% } %>
for controlling on loading page / process.
Brian's answer is a good advice, but it does not answer the question clearly.
The answer is YES. Bulk of JSP is converted to a method _jspService, which is being run when JSP is "executed", and since it is a regular function, that does cleanup in finally block, it is safe to return.
If you really really want to do this I would suggest something like the following
..some jsp.. <% if (iWantToKeepProcessing) { %> ..someother stuff.. <% } %>
I have to agree with Brian though and say that you should avoid entering the JSP if possible. This might not be available to you if you are handling a post/get directly targeting a dynamic JSP file rather than a controller/servlet.
Since 2.0, there is a standard way:
throw new javax.servlet.jsp.SkipPageException();