Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

rationale for jspInit() not throwing ServletException

 
Mike Curwen
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' ?
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • 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?
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My favorite:
Why don't I understand questions like this?
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac 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
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13056
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic