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

URL mappings

 
Sophie Angela
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In URL mappings in Deployment descriptor, for a extension mapping is it nessesary that we need to give the *.do or *.hd or *.<anything>?
Simply can we leave it as <utl-pattern>*</url-pattern>
 
Kai Witte
Ranch Hand
Posts: 356
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello,

just whatever you wish to map. The .do extension has no special meaning. If you map * all requests of the entire web application would be handled by a single Servlet or JSP. Usually that is not a good idea.

The URIs in that mapping should be well chosen if they are accessible from the outside (and not proxied through a web server or something).

Kai
 
Tiffiny Yang
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A question about URL mappings:

If no URL mappings in web.xml, I can't get the init parameter by using
getServletConfig().getInitParameter("XX"), why is that?

Thanks.
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If no URL mappings in web.xml, I can't get the init parameter by using
getServletConfig().getInitParameter("XX")

If you have no mapping in web.xml, you can't access the servlet, so the question of init parameters is moot.
 
Tiffiny Yang
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Without URL Mapping, I can access my servlet by invoking with full package
http://localhost:8080/servlet/coreservlets.HelloServlet

while with URL mapping coreservlets.HelloServlet to Hello, then I can invoke the servlet using short
http://localhost:8080/servlet/Hello

So, now my question is why can't I get Initialization Parameters without URL mapping, I don't see the reason...
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The invoker servlet (which is what the URL http://localhost:8080/servlet/coreservlets.HelloServlet uses) is a nasty way of invoking servlets, and not part of the servlet spec (see InvokerServlet for more info).

Without a mapping, how would you even specify initialization parameters? A servlet will only be initialized once a URL that it is mapped to gets accessed. Without a mapping, no access, and no initialization.

The fact that you can access a servlet without a mapping seems to point to a non-standard feature of the servlet container.
 
Tiffiny Yang
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's the example of Getting and Setting Initialization Parameters for a Servlet without URL mapping.

http://www.exampledepot.com/egs/javax.servlet/GetInit.html?l=rel
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic