• 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
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

URL-PATTERN Confusion

 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The Url-pattern in the web.xml file has always kind of confused me so I hope I can get some clarification.
I have a small little test web app. I have a JSP page which submits a single text field to a Servlet. My JSP page is in a pages directory.
Ok, so in my web.xml file the url-pattern for my Servlet is /actions/LoginServlet.
Now, as long as my webapp is the ROOT web app in Tomcat, I can submit to the servlet via action="/actions/LoginServlet".
Now, if I put my webapp in its own folder, and try and access my Servlet, it, of course, takes me back to the ROOT and can't find the servlet.
So my question is, how do I write the url-pattern so that my servlet is accessable relative to the location of my WEBAPP.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I changed my action in my form to "../actions/LoginServlet". This seems to do the trick rather the web app is the ROOT web app or in it's own context.
Is this correct what I did?
 
Chicken Farmer ()
Posts: 1932
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The / goes to the root of your webapp, the display name that is defined in web.xml.
So if you have a webapp called "test", if you set up a servlet mapping with url-pattern /actions/LoginServlet, then the URL http://localhost/test/actions/LoginServlet will work.
However, I believe the FORM action interprets / as the root of the host, so what you end up with is http://localhost/actions/LoginServlet, which sends you to the ROOT webapp. The mapping you set up is in terms of the test webapp, though. They are independent of each other.
Doing ../actions/LoginServlet moves you back one from the pages directory, which puts you back at the test root. You could also do the following:
action="/test/actions/LoginServlet"
That's my preferred method, it ensures you are going to the right place, just in case your pages directory structure changes.
If the login.jsp page was directly under the test webapp (the "test" directory), then you could also do action="actions/LoginServlet".
Hope that helps some.
[ September 15, 2003: Message edited by: jason adam ]
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That explains it perfectly Jason. I thought I was missing something, but it really is as simple as it appears.
Thanks.
 
reply
    Bookmark Topic Watch Topic
  • New Topic