Dónal
Dónal

Reputation: 187499

throw exception from a JSP

Is it possible to throw an exception in a JSP without using scriptlet code?

Upvotes: 4

Views: 6066

Answers (3)

Heath Borders
Heath Borders

Reputation: 32107

You really shouldn't be doing anything at the JSP layer that explicitly throws exceptions. The reason you don't want to use scriptlets in JSPs is because that puts application logic in your view. Throwing an exception is inherently application logic, so it doesn't belong in your JSP, scriptlet or not.

Upvotes: 9

sblundy
sblundy

Reputation: 61414

You could have a bean with a getter method that throw the code, then have the JSP access the bean property. I'm not sure that'd be an actual improvement over a scriptlet.

Upvotes: 0

Swati
Swati

Reputation: 52707

You can throw an exception if you do this:

<c:out value="${1/0}" />

or something that is similarly "illegal"

Ideally though, since JSPs are associated with the view...you don't want to throw an exception. You want to catch them with <c:catch>

Upvotes: 0

Related Questions