Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
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

Couple of doubts

 
Prasad Joglekar
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I have a couple of doubts related to servlets/JSPs:

1. What is the exact sequence in which various web-app components are loaded (i.e. filters, listeners, context, servlets, etc...).

2. How are HTTP methods resolved for direct client calls to JSPs? For instance, if I do POST from a page to a JSP, how does the container know that it is to use doPost when none is explicitly implemented?

3. Can someone post the grammar / Regular Expression rules (if either exists) used for matching the input URL to servlet mappings?

Thanks and Regards,
Prasad
 
satishkumar janakiraman
Ranch Hand
Posts: 334
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi prasad,

What is the exact sequence in which various web-app components are loaded (i.e. filters, listeners, context, servlets, etc...).


Context, filters, listeners and servlets



How are HTTP methods resolved for direct client calls to JSPs? For instance, if I do POST from a page to a JSP, how does the container know that it is to use doPost when none is explicitly implemented?


Jsp is nothing but servlet. HttpServlet class provides the empty implementation for each of the doXXX() . First the container will call the service(ServletRequest req, ServletResponse res) of the HttpServlet.Second, this service method calls the service(HttpServletRequest req, HttpServletResponse res) of the same class. Third This method analyse the request and finds out which method is being used.Depending on the HTTP method, it calls the appropriate doxxx().

I hope, this will help you

I dont know the answer for your 3rd question


bye for now
sat
 
Narendra Dhande
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Some confusion.

The inilialization order is context,filters, listeresr, servlets

When the context is initialized, the contextInitialized method of ContextListener is invoked, so I think atleast ContexListerers are initialized immediately after context initialization. I think it is not necessary to initialized filters and servlet at the start of application ( For servlet, unless the <load-on-startup> is mentioned in DD.


In case of generated Servlet there is no doXXX() methods. There is only on all in one _jspService method which process all types of requests and directly called by Servlet service() method.

The servlet mapping rules ( These are not regular expressions ) can be found in servlet specs. There is serpeate chapter on it SVR.11 Mapping Servlets to Requests.

Please confirm if any diversions.

Thanks
 
Rizwan Mohammad
Ranch Hand
Posts: 445
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Servlet container performs following things in order before service method servlet gets called.
1. initialize listners.
2. context initialize method gets called.
3. create filters
4. create servlets.
 
rakesh mittal
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rizwan:
Servlet container performs following things in order before service method servlet gets called.
1. initialize listners.
2. context initialize method gets called.
3. create filters
4. create servlets.


hi
there is some confusion between 1 and 2 option,
there is one listener(http session binding listener)
that we dont declare in dd.
so how it can be initialized before context
 
Narendra Dhande
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

If the context is initialized after listeners, how the context listeners get reference to the ServletContext.

Thanks
 
Vasanth Raja.K.
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,
This is the order i found in Spec.

� Instantiate an instance of each event listener identified by a <listener> element in the deployment descriptor.
� For instantiated listener instances that implement ServletContextListener,
call the contextInitialized() method.
� Instantiate an instance of each filter identified by a <filter> element in the deployment descriptor and call each filter instance�s init() method.
� Instantiate an instance of each servlet identified by a <servlet> element that includes a <load-on-startup> element in the order defined by the load-on startup element values, and call each servlet instance�s init() method.


Reg
Vasanth
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic