File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes rationale for jspInit() not throwing ServletException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "rationale for jspInit() not throwing ServletException" Watch "rationale for jspInit() not throwing ServletException" New topic

rationale for jspInit() not throwing ServletException

Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

Is there one?

For a regular servlet, we have the following signature:
public void init(ServletConfig config) throws ServletException

For a JSP page:
public void jspInit()

There is a note in the text of jspInit method that says: invocations to the getServletConfig() method will return the desired value. So we can at least retrieve a ServletConfig object, rather than having it passed in. But why wouldn't I be able to throw an Exception and have the JSP page 'unavailable' ?
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199

Dunno, good question.
My favorite:
Why does java.beans.PropertyChangeSupport not have a protected constructor that assumes the current object is the event source, so you could subclass it?

[Jess in Action][AskingGoodQuestions]
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15302

My favorite:
Why don't I understand questions like this?

GenRocket - Experts at Building Test Data
Mark Spritzler

Joined: Feb 05, 2001
Posts: 17276

An uneducated guess. As we know JSPs are converted into Servlets by the container. So the jspInit is not directly implemented in the created Servlet. I would guess that the container takes what is in this method and put it into the Servlet's init method, which would be written for you throwing the ServletException.
Plus is ServletException even available in a JSP page? The name of the Exception itself kind of answers that in that it isn't called JSPException.
So that is my guess.
But good question and I would be interested in finding out the real answer.

Perfect World Programming, LLC - iOS Apps
How to Ask Questions the Smart Way FAQ
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13036
It looks to me like jsp_init is some sort of dummy. Here is part of the generated code for the Tomcat example numguess.jsp. It does NOT have a custom jsp_init - instead, the service method checks to see if _jspx_init has been called, and _jspx_init does throw an exception.

I agree. Here's the link:
subject: rationale for jspInit() not throwing ServletException
It's not a secret anymore!