File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes How does the url Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "How does the url "webappname/servlet/..." work well?" Watch "How does the url "webappname/servlet/..." work well?" New topic

How does the url "webappname/servlet/..." work well?

Simeon Shi
Ranch Hand

Joined: Dec 09, 2001
Posts: 35
First, the following is the physical path of my web application.
│ └classes
│ │ └webapplication
│ │ └AccountServlet.class
│ │ └LoginServlet.class
│ └web.xml
└ login.html

I try to access the URL "",which the login.html post a request to the servlet LoginServlet which is in the package webapplication.Then the LoginServlet will redirect to the AccountServlet if the login is ok.I use the req.getRequestDispatcher("/AccountServlet").forward(req, res) to get the user's account info.However, the question arised here.In the book, it use the req.getRequestDispatcher("/servlet/AccountServlet").forward(req, res) and also will sucess.It is strange about the /servlet/... What does the path means?I don't have such package or directory.
I tried some other web application then and I found that the path "/servlet/..." all work well.Can anyone help me?
[ September 12, 2002: Message edited by: simeon shi ]
Mark Howard
Ranch Hand

Joined: Feb 14, 2001
Posts: 285
Hi Simeon
Good question. Confuses me as well. I think the /servlet is a default directory in the Servlet deployment structure.
See this link in the SCWCD thread, where similar concerns are raised.

Joined: Sep 02, 2002
Posts: 2
You should view web.xml file to see servlet mapping configration.
For example:

<!-- Action Servlet Mapping -->
Then you can visit ActionServlet.class through the url "http://localhost/Servlet/ActionServlet"
Hope it can help you.
Simeon Shi
Ranch Hand

Joined: Dec 09, 2001
Posts: 35
Actually,I made the web.xml by myself in which I didn't assign the <servlet-mapping> tag.
I agree. Here's the link:
subject: How does the url "webappname/servlet/..." work well?
jQuery in Action, 3rd edition