开发者

Is there command to stop execution of the jsp file?

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜