views:

742

answers:

3

Hi,

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

Cheers, Don

A: 

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>

Swati
A: 

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.

sblundy
+5  A: 

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.

Heath Borders