I have a JSP file that contains lots of if statements.
开发者_开发技巧Is there a way to stop execution of file on demand?
For example:
Can I change:
if (x==y) {
...
} else {
...
}
to:
if (x==y) {
....
stopExecution();
}
....
As you already found out, you can return;
to "stop" execution.
This works because Java code is generated from the JSP with
public void _jspService(HttpServletRequest request, HttpServletResponse response)
throws java.io.IOException, ServletException {
// ...
}
method being the entry point. If you write a return
in that code, the method will return. You can check out the generated code in tomcat under $TOMCAT/work/Catalina
.
You could use labels within Java, like:
out: {
if( x == y) break out;
........................
}
So you can put a lot of if's in the label and then break out of the whole code inside the brackets.
精彩评论