wood burning stoves 2.0*
The moose likes Servlets and the fly likes what should be the first servlet to display when application launches? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "what should be the first servlet to display when application launches?" Watch "what should be the first servlet to display when application launches?" New topic
Author

what should be the first servlet to display when application launches?

jazy smith
Ranch Hand

Joined: Nov 18, 2009
Posts: 101
hi all,

I am new to servlets. I want to know how the server decides what servlet should be called very first when app is being launched. Please explain me referring web.xml.

in details : suppose in web.xml , there are 5 servlets and one welcome file . In this 5 servlets there is one action servlet also. so how can I know what servlet would get called first.

Hope you got my question.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60802
    
  65

No servlet gets called when the app launches. Servlets are invoked as a result of requests.

If you need activity to take place at app launch, that is what context listeners are for.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
jazy smith
Ranch Hand

Joined: Nov 18, 2009
Posts: 101
i didn't get you. can you please explain in detail? i appreciate your efforts . thanks in advance
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60802
    
  65

What's to explain? When the app launches, no servlet gets automatically is invoked.

A servlet will not be invoked until a request for it arrives from a client.
jazy smith
Ranch Hand

Joined: Nov 18, 2009
Posts: 101
thanks. i got it now.
Nishan Patel
Ranch Hand

Joined: Sep 07, 2008
Posts: 684

Bear Bibeault wrote:What's to explain? When the app launches, no servlet gets automatically is invoked.

A servlet will not be invoked until a request for it arrives from a client.


Yes, I think you you can not call servlet without fire any request, but Bear I think we can load servlet at container using
[code <load-on-startup>1</load-on-startup>[/code] ....

correct me if I was wrong....


Thanks, Nishan Patel
SCJP 1.5, SCWCD 1.5, OCPJWSD Java Developer,My Blog
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60802
    
  65

Loading and invoking are two very different things.
dhaval yoganandi
Ranch Hand

Joined: Jun 06, 2009
Posts: 35

Bear Bibeault wrote:Loading and invoking are two very different things.


agreed with Bear Bibeault.

Loading and Invoking are two different things. Loading a servlet call init method of the servlet it won't call any service methods of the servlet. And invoking a servlet mean you are calling the service methods.





a.k.a stalker.
jazy smith
Ranch Hand

Joined: Nov 18, 2009
Posts: 101

Loading and Invoking are two different things. Loading a servlet call init method of the servlet it won't call any service methods of the servlet. And invoking a servlet mean you are calling the service methods.


Perfect answer. This is what my doubt was .. thanks a lot.
jazy smith
Ranch Hand

Joined: Nov 18, 2009
Posts: 101
Bear Bibeault wrote:Loading and invoking are two very different things.


Bear, so you mean <load-on-startup> tag only loading the servlet into memory i.e. creates object of the servlet. But if you want to invoke it, you have to explicitly call that servlet by typing the exact path of that servlet in URL. Am I right ?

another question is : when there is <welcome-file> xyz.jsp <welcome-file> tag in web.xml, the container will display xyz.jsp on the screen when the server is started first time. is it correct ?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60802
    
  65

jazy smith wrote:when there is <welcome-file> xyz.jsp <welcome-file> tag in web.xml, the container will display xyz.jsp on the screen when the server is started first time. is it correct ?

Of course not. What screen would it display it on?
jazy smith
Ranch Hand

Joined: Nov 18, 2009
Posts: 101
Of course not. What screen would it display it on?


screen means when you run the project manually by clicking on run button in eclipse, the browser will get opened and the first page on the browser will be xyz.jsp. this is what i wanted to ask. If I am wrong, please let me know what <welcome-file> tag exactly does ? I really appreciate your help.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60802
    
  65

Eclipse is not the real world.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60802
    
  65

The welcome file tag defines what URL to use when none is specified.
jazy smith
Ranch Hand

Joined: Nov 18, 2009
Posts: 101
hi, suppose i have fully qualified class "project_name/1/2/3/4/hi.java" and I want to display hi.java as my main web page. So, i will include this file in <welcome-file> in web.xml by <servlet-mapping> and <url-pattern>. Now here is my question. if I write <welcome-file>hi.java</welcome-file> how would container come to know the exact location of hi.java ? (i.e. what hi.java I am referring to ? ) Please let me know what do i have to write in <welcome-file> tag to display hi.java as a main web page ?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60802
    
  65

It needs to be the context-relative URL to the resource.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: what should be the first servlet to display when application launches?
 
Similar Threads
how to know which servlet/jsp calling a particular servlet
xml mapping Head First Servlets and JSP
doubt in forwarding
some basic questions
Servlet class