This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
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

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

 
jazy smith
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64633
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
jazy smith
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i didn't get you. can you please explain in detail? i appreciate your efforts . thanks in advance
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64633
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks. i got it now.
 
Nishan Patel
Ranch Hand
Posts: 689
Eclipse IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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....
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64633
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Loading and invoking are two very different things.
 
dhaval yoganandi
Ranch Hand
Posts: 35
Android Linux VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.




 
jazy smith
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64633
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64633
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eclipse is not the real world.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64633
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The welcome file tag defines what URL to use when none is specified.
 
jazy smith
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64633
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It needs to be the context-relative URL to the resource.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic