aspose file tools
The moose likes Servlets and the fly likes RequestDispatcher.forward() is init()ing servlet? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Servlets
Reply Bookmark "RequestDispatcher.forward() is init()ing servlet?" Watch "RequestDispatcher.forward() is init()ing servlet?" New topic
Author

RequestDispatcher.forward() is init()ing servlet?

Brian Mulholland
Ranch Hand

Joined: Mar 12, 2009
Posts: 54
Okay, we have a weird situation. We have an app that has been in maintenance mode for a long time. A recent change moved some code that was in teh servlet context listener to the servlet init method. The context listener was firing first of course, and the code required some resources that weren't available until servlet init.

Anyway, moving this code caused us to either notice something we never noticed before or cause something. The something is that under some conditions, the servlet init is throwing an exception where the stack trace reveals that it was invoked as a downstream consequence of RequestDispatcher.forward(). This is in an application that already ran the initialization and has load-at-startup on in web.xml.

This baffles me. If you ran init already, why would forward() call init() again?
Anurag Verma
Ranch Hand

Joined: Mar 30, 2012
Posts: 118

init is called just once in a servlet life cycle. do you have a call to init method within your code by any chance?
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Brian Mulholland wrote: The something is that under some conditions, the servlet init is throwing an exception where the stack trace reveals that it was invoked as a downstream consequence of RequestDispatcher.forward(). This is in an application that already ran the initialization and has load-at-startup on in web.xml.

how you are getting the request and response either in ServletContextListener or init of servlet?
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: RequestDispatcher.forward() is init()ing servlet?
 
Similar Threads
Logging inside Context Listener
richfaces and problems with navigation
Registering Listeners in web.xml
help me with this objective
ServletContextListener v/s init() method