ufk
ufk

Reputation: 32104

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();
}
....

Upvotes: 2

Views: 4155

Answers (2)

David
David

Reputation: 680

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.

Upvotes: 4

Tahir Malik
Tahir Malik

Reputation: 6643

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.

Upvotes: 1

Related Questions