• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Mapping Resources from DD

 
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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"
 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Reema Patel
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic