Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

rationale for jspInit() not throwing ServletException

 
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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' ?
 
author and iconoclast
Posts: 24203
43
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My favorite:
Why don't I understand questions like this?
 
ranger
Posts: 17346
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Mark
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Bill
 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic