Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Path to servlet

 
Andrew Parker
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I created a servlet which included in a package com.abc.web.Checkin and the class is CheckinServlet.
I created a dir "abc" under /var/tomcat4/webapps/. So, /var/tomcat4/webapps/abc/index.jsp will be shown when I browsed it at http://localhost:8080/abc/index.jsp.
In the index.jsp, I have a form action=/abc/servlet/com.abc.web.Checkin.CheckinServlet
And the CheckinServlet.class was placed in /var/tomcat4/webapps/abc/WEB-INF/classes/com/abc/web/Checkin/CheckinServlet.class.
However, the browser returns that there is no such page: http://localhost:8080/abc/servlet/com.abc.web.Checkin.CheckinServlet
Why and how can I fix this problem? Where should I place the servlet and be defined in form action?
Thanks
Andrew
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13071
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You would be better off creating an entry for the servlet in the web.xml for your "abc" web application. That way you could address it with a short URL. See the Tomcat examples/WEB-INF/web.xml for examples with explanation.
Download the servlet API from java.sun.com for the full details on what goes in a web.xml.
Bill
 
Andrew Parker
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Sir,
In fact, I have a web.xml file which located at /webapps/abc/WEB-INF/web.xml.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<servlet>
<servlet-name>CheckinServlet</servlet-name>
<servlet-class>com.abc.web.Checkin.CheckinServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>CheckinServlet</servlet-name>
<url-pattern>/CheckinServlet</url-pattern>
</servlet-mapping>
</web-app>
But, it still did not work. Any idea?
Regards
Andrew
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In web.xml, the <servlet> element should be thought of as "back-end" and hidden.

The <servlet-mapping> on the other hand, is the opposite. It is the front-side and 'public' interface to your application classes.

So in this case, your form action tag should be submitting to "/CheckinServlet", not the fully qualified class name of what should be a private class.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic