File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Simeon Shi
Ranch Hand
Posts: 35
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First, the following is the physical path of my web application.
...
---BankAccount
└ WEB-INF
│ └classes
│ │ └webapplication
│ │ └AccountServlet.class
│ │ └LoginServlet.class
│ └web.xml
└ login.html

I try to access the URL "http://127.0.0.1:8080/BankAccount/login.html",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
Posts: 285
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
tonyqu
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should view web.xml file to see servlet mapping configration.
For example:
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
</servlet>

<!-- Action Servlet Mapping -->
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>/Servlet/ActionServlet</url-pattern>
</servlet-mapping>
Then you can visit ActionServlet.class through the url "http://localhost/Servlet/ActionServlet"
Hope it can help you.
 
Simeon Shi
Ranch Hand
Posts: 35
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually,I made the web.xml by myself in which I didn't assign the <servlet-mapping> tag.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic