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