Need help w. servlet packaging.

S

Steve R. Burrus

I have posted to this newsgroup before about this problem, but it sadly
remains unresolved successfully for me, and that is the proper package
structure for a servlet! Now, in the package statement at the top of the
servlet file, and assuming that I am using Tomcat for my servlet container,
should the path be something like "C:\tomcat
5.0\webapps\[context-folder]\web-inf\classes\[org\steve\burrus]" where the
compiled servlet class file "resides"??! And, re. the web.xml file, i.e.,
the web descriptor file, should the contents of the <servlet-class> tag
"mirror" the end of that path above, "org\steve\burrus" appended in front of
the servlet class name? I tell you what, I am getting quite sick and tired
of always seeing that "blasted" old 404 server error page every time that I
try/attempt to execute a Java servlet. It's "driving me nuts" when I have to
see this. I will bet that some in this group, with all that they know about
servlets, NEVER see this page. Thanx in advance for any help that I may get.
 
R

Ryan Stewart

Steve R. Burrus said:
I have posted to this newsgroup before about this problem, but it sadly
remains unresolved successfully for me, and that is the proper package
structure for a servlet! Now, in the package statement at the top of the
servlet file, and assuming that I am using Tomcat for my servlet container,
should the path be something like "C:\tomcat
5.0\webapps\[context-folder]\web-inf\classes\[org\steve\burrus]" where the
compiled servlet class file "resides"??! And, re. the web.xml file, i.e.,
the web descriptor file, should the contents of the <servlet-class> tag
"mirror" the end of that path above, "org\steve\burrus" appended in front of
the servlet class name? I tell you what, I am getting quite sick and tired
of always seeing that "blasted" old 404 server error page every time that I
try/attempt to execute a Java servlet. It's "driving me nuts" when I have to
see this. I will bet that some in this group, with all that they know about
servlets, NEVER see this page. Thanx in advance for any help that I may get.
For a simple, no-package servlet:
The class file goes in WEB-INF/classes. Assume a "Hello world" servlet named
Hello.class. Using Tomcat, Hello.class goes in
$CATALINA_HOME/webapps/<context folder>/WEB-INF/classes. The relevant parts
of web.xml are as follows:
<servlet>
<servlet-name>hello</servlet-name>
<servlet-class>Hello</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>hello</servlet-name>
<url-pattern>/hello</url-pattern>
</servlet-mapping>

The servlet-name must correspond between the servlet and servlet-mapping.
The servlet-class is the fully qualified name of the servlet file. The
url-pattern is what you put in the address bar after the context to access
the servlet. The URL to access the servlet would be something like:
http://localhost:8080/myContext/hello

To move our imaginary Hello servlet to a package, such as org.steve.burrus,
there are only a few steps:
1) Obviously, put "package org.steve.burrus;" at the top of the .java file
and recompile.
2) Put Hello.class in WEB-INF/classes/org/steve/burrus.
3) In web.xml, change:
<servlet-class>Hello</servlet-class>
to:
<servlet-class>org.steve.burrus.Hello</servlet-class>

I think that's it. Did I miss anything anybody?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,001
Messages
2,570,254
Members
46,849
Latest member
Fira

Latest Threads

Top