aspose file tools*
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


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Mapping Resources from DD" Watch "Mapping Resources from DD" New topic
Author

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/test.do 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("test.do");
OR
(b) request.getRequestDispatcher("/test.do");
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/test.do", Why is the app name (king) required?

Any help shall be highly appreciated.

Thanks
Reema
Akbar Upadyayula
Greenhorn

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

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

2.
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.

3.
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">
<web>
<web-uri>KingWar.war</web-uri>
<context-root>king</context-root>
</web>
</module>

So when you go for the request king/test.do 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
ServletContext..

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



Regards


saivenumadhav
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
Greenhorn

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

you need to mention like this..
<url-pattern>/test.do</url-pattern>
king is yor context name ...right in browser first you need to type like
"http://hostname:1100/king"
it identifies your web.xml file in other sence browser points to your application context...
from ther you need to mention "test.do" in action tag of HTML page.
that will directly invokes coresponding servlet
 
 
subject: Mapping Resources from DD