• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

default URL and custom URL

 
Thambi Rajah
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The web.xml file looks the following:

In LoginServlet class, doPost method has the following code:

We try to access the LoginServlet in three ways.
(1) default URL
http://localhost:8080/demo/servlet/LoginServlet
(2) Registered Name
http://localhost:8080/demo/servlet/anyName
(3) custom URL
http://localhost:8080/demo/login
When we access through default URL, we get Region= null in the output.
When we access through Registered Name or custom URL, we get Region= North America in the output.
Can somebody explain this results?
Thanks in advance,
Thambi
 
Kyle Tang
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is about how many servlet instances web-container will create for you.
for each <servlet-name>, web-container will create one servlet instance, this instance, is only accessed by the <url-pattern> that is mapped.
(NOT the default /servlet/* invoker pattern). and of course the init params you defined will be available.
if you use the default /servlet/* invoder pattern, the web-conainter will access another servlet instance, which is not defined in any <servlet-name>, here in your sample web.xml file, there is no init parameter defined, so it is null.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic