Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exception in Servlet Init()

 
Gagan Indus
Ranch Hand
Posts: 346
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

If a servlet throws
- ServletException
- More specific subclass , UnavialableException
in its init() method , then what are course of actions web-container takes :
- Immediately
- And for future requests for this servlet
Plz clarify
Thankx in advance
------------------
Gagan (/^_^\) SCJP2
Die-hard JavaMonk -- little Java a day , keeps u going .
 
Tim Duncan
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See Section 2.3.2.1 of the Servlet spec (p.24)
 
Gagan Indus
Ranch Hand
Posts: 346
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thankx Tim

yes i been following spec 2.3.2.1 , but i am not very clear about what it wanna say .
Like if my servlet throws ServletException randomly in init() as:
random = new Random();
if(random.nextBoolean())
throw new ServletException("custom message");

Than for the first request , it shows servlet exception with custom message ,
all further requests are replied with :
"The requested resource (/exceptionapp/servlet/Serve) is not available"
And if my servlet throws UnavailableException randomly in init() as:
random = new Random();
if(random.nextBoolean())
throw new UnavailableException("custom message");

Than for all requests to this servlet are responded with
"The requested resource (/exceptionapp/servlet/Serve) is not available"

But one part of spec2.3.2.1 says :
...A new instance may be instantiated and initialized by the container after a
failed initialization....
So what are those conditions , under which container will try make new instance for further requests , even after one failed initilization ?

------------------
Gagan (/^_^\) SCJP2
Die-hard JavaMonk -- little Java a day , keeps u going .
 
Carl Trusiak
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anytime the specs say "May", this means that it is implementation specific. Check the Doc's for your Server to determine what it will do or setup some test servlets and see.
------------------
I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
 
Gagan Indus
Ranch Hand
Posts: 346
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thankx Carl


...or setup some test servlets and see...


So what you think , i was *guessing* those outputs?
I did setup those servlets , and then only posted my question

------------------
Gagan (/^_^\) SCJP2
Die-hard JavaMonk -- little Java a day , keeps u going .
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic