Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlet package and Tomcat Question

 
Art Smith
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I use JBuilder Foundation to edit and compile my servlets. Jbuilder creates a package for each project and places all of the classes for that project in the package.
Do I have to include tha package path under my classes dir with Tomcat. In other words:
// Top few lines from my Servlet
package servlets;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
// Entry from my web.xml file
<servlet>
<servlet-name>
TestServlet
</servlet-name>
<servlet-class>
TestServlet
</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>
TestServlet
</servlet-name>
<url-pattern>
/TestServlet
</url-pattern>
</servlet-mapping>
// Context as defined in my server.xml file
<Context path="/hallanet"
docBase="webapps/hallanet"
crossContext="false"
debug="0"
reloadable="true" >
</Context>
Directory Structure under webapps in tomcat:
D:\ApacheGroup\Tomcat\jakarta-tomcat-3.2.1\webapps\hallanet\Web-inf\classes
How do I corrlate these files, packages and paths so that MY servlets will run.
NOTE: The Tomcat examples; servlets and JSP's work just fine.
Art
 
Roopa Bagur
Ranch Hand
Posts: 267
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whatever you have done loos fine to me.
What message are you getting when you run your servlet?
Originally posted by Art Smith:
I use JBuilder Foundation to edit and compile my servlets. Jbuilder creates a package for each project and places all of the classes for that project in the package.
Do I have to include tha package path under my classes dir with Tomcat. In other words:
// Top few lines from my Servlet
package servlets;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
// Entry from my web.xml file
<servlet>
<servlet-name>
TestServlet
</servlet-name>
<servlet-class>
TestServlet
</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>
TestServlet
</servlet-name>
<url-pattern>
/TestServlet
</url-pattern>
</servlet-mapping>
// Context as defined in my server.xml file
<Context path="/hallanet"
docBase="webapps/hallanet"
crossContext="false"
debug="0"
reloadable="true" >
</Context>
Directory Structure under webapps in tomcat:
D:\ApacheGroup\Tomcat\jakarta-tomcat-3.2.1\webapps\hallanet\Web-inf\classes
How do I corrlate these files, packages and paths so that MY servlets will run.
NOTE: The Tomcat examples; servlets and JSP's work just fine.
Art

 
Scott Stirling
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you have to include the package under the WEB-INF\classes dir.
You also have to define the servlet using its fully qualified class name, so TestServlet should be:
<servlet>
<servlet-name>TestServlet</servlet-name>
<servlet-class>servlets.TestServlet</servlet-class>
</servlet>
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
D:\ApacheGroup\Tomcat\jakarta-tomcat-3.2.1\webapps\hallanet\Web-inf\classes
I would use either the web.xml or the server.xml not both.
I prefer the older way of server.xml, personally.
Also, to understand this better, pl. refer to this article
where they walk you thru such an example
.
Do I have to include tha package path under my classes dir with Tomcat
Yes you do have to.
So your dir structure should be:
webapps/hallanet/WEB-INF/classes/servlets/TestServlet.class
regds.
- satya
 
Art Smith
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Scott - You win the prize. That was it! This single line of code:
servlets.TestServlet
Solved my problems.
THANKS A LOT!
Art
Originally posted by Scott Stirling:
Yes, you have to include the package under the WEB-INF\classes dir.
You also have to define the servlet using its fully qualified class name, so TestServlet should be:
<servlet>
<servlet-name>TestServlet</servlet-name>
<servlet-class>servlets.TestServlet</servlet-class>
</servlet>

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic