File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Mapping Resources from DD Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Mapping Resources from DD" Watch "Mapping Resources from DD" New topic

Mapping Resources from DD

Reema Patel
Ranch Hand

Joined: Jan 26, 2006
Posts: 169
Hello All,
I have three basic queries.

Pls. consider the DD

1. My web app's name is 'king'. I believe that in the <url-pattern> tag I need not give a /king/ path, i-e there's no need to precede the web app name here. But, why is it that way?

2. In a servlet, If i obtain a RequestDisatcher through a request, I have two oprions:
(a) request.getRequestDispatcher("");
(b) request.getRequestDispatcher("/");
Both options work, but, which one is better?

3. If I want to connect to TestServlet from a HTML page, I need to give
href="/king/", Why is the app name (king) required?

Any help shall be highly appreciated.

Akbar Upadyayula

Joined: Feb 09, 2007
Posts: 12
Hi Reema,

for identifing the context you should always mention the app's name

The pathname specified cannot extend outside the current servlet context. If the path begins with a "/" it is interpreted as relative to the current context root.
and requestdispature always points to current context.

HTML means completly at client side so that HTML page don't know about yor app's name or context name so you need to mention complete url in "href"
madhav changala
Ranch Hand

Joined: Dec 20, 2005
Posts: 57
Hello reema,

1)For every web application there is war file ,so in application.xml or someother file give the name and will map with contextroot name.It will be as below
<module id="WebModule_1155931475921">

So when you go for the request king/ first it will find out the context root .. here king.. then go to the corresponding war file.. As you know for every war file there will be web.xml from there it identify the Servlet for which the request will be delegate,,,,

This is how the whole process will be going.. dont confuse with application.xml simply takes that it is war file name... king..

2)Actually there are two ways of getting RequestDispatcher,, one is from ServletRequest

when you go for Servletcontext the path must start with "/" .. as it has to start from context root..

when you go for ServletRequest the path may or may not start with"/" ..

which is better means? i dont know exactly..

3)For this Akbar given nice answer,,

If you still having doubts.

Pls feel free to post


Reema Patel
Ranch Hand

Joined: Jan 26, 2006
Posts: 169
Thanks Akbar and Madhav.
But, I still have a query.
Akbar's post-
"for identifing the context you should always mention the app's name"

But, in url-pattern tag I just need to mention the logical resource's name..right?

I also tried this:

This gave me 404 Not Found.

Is my understanding correct?
Akbar Upadyayula

Joined: Feb 09, 2007
Posts: 12
you are right?

you need to mention like this..
king is yor context name ...right in browser first you need to type like
it identifies your web.xml file in other sence browser points to your application context...
from ther you need to mention "" in action tag of HTML page.
that will directly invokes coresponding servlet
Consider Paul's rocket mass heater.
subject: Mapping Resources from DD
It's not a secret anymore!