Reputation: 187399
Is it possible to throw an exception in a JSP without using scriptlet code?
Upvotes: 4
Views: 6086
Reputation: 32197
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
Reputation: 61434
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
Reputation: 52847
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