wood burning stoves 2.0*
The moose likes Servlets and the fly likes Servlet Package question of mine. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet Package question of mine." Watch "Servlet Package question of mine." New topic

Servlet Package question of mine.

Mark Spritzler

Joined: Feb 05, 2001
Posts: 17249

I should know this but here is my dilemna.
I have two packages com.sasco.xml and com.sasco.ccreview
In these packages I have two class in the com.sasco.xml and one class in the ccreview. The class in the ccreview package is an HTTPServlet.
I have the directory structure correct in my development directory and the class path set to the root of this development directory, and therefore compiling is fine.
I am no transferring this servlet and helper classes to Tomcat's webapps/root directory. in this directory I created a directory called ccreview. I put the com/sasco/xml and com/sasco/ccreview directories in this subdirectory, changed the web.xml document in the web-inf directory to include the following

I also have an html form page that the action of the submit button is <form action="CCReview">
The form is located in the ccreview directory, so when submit is clicked it looks for CCReview/CCReview, but alas I get a 404 error.
Do I need to have the servlet .class file in the com.sasco.ccreview directory, or should it be in my web apps root directory with the html document.

Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

should be something like:
And your web.xml has one too many CCReview's in it.

When the form is submitted, it's submitted the servlet that is mapped to the matching <url-pattern>.
BJ Grau
Ranch Hand

Joined: Jul 10, 2001
Posts: 234
Make your form submit like this:
<form action="/CCReview">
And change your servlet mapping to look like this:

This way your form will submit to www.yourapp.com/CCReview and the servlet mapping will read this and invoke the right servlet.
Where you keep your servlets varies depending on the container, but my co-worker is telling me that for Tomcat servlets go under classes, so keep your CCReview servlet in classes/com/sasco/ccreview
I'm sure I forgot something, but give this a try.
Good luck.
Mark Spritzler

Joined: Feb 05, 2001
Posts: 17249

Cool. Now I am getting a ServletException
javax.servlet.ServletException: Wrapper cannot find servlet class com.sasco.ccreview.CCReviewServlet or a class it depends on
I had to create the classes directory into the webapps directory as Tomcat did not create this directory for me. Could this be where the problem is.
There is a classes directory at Tomcat's root, but not in it's webapps subdirectory.
Thanks for you help.
Karl Moss

Joined: Feb 08, 2002
Posts: 18
Where did you create the classes subdirectory? It should go under the WEB-INF directory of the webapp:
You can also jar up your classes into a library if you would like and place them in the lib directory:
These directories may (or may not) be created for you by the servlet container.

Karl Moss,<br />Author of <a href="http://www.amazon.com/exec/obidos/ASIN/007222262X/ref=ase_electricporkchop" target="_blank" rel="nofollow">Java Servlets Developer's Guide</a> <br /><a href="http://www.servletguru.com" target="_blank" rel="nofollow">ServletGuru.com</a> the Companion site.
Mark Spritzler

Joined: Feb 05, 2001
Posts: 17249

Thanks Karl, that was my problem. I put the com directory there and now my servlet fires.
Putting this thread to bed, and starting a new one on my lastest problem.
I agree. Here's the link: http://aspose.com/file-tools
subject: Servlet Package question of mine.
Similar Threads
Calling a servlet from a html page
HFSJ book: Cookie example chapter 6 plz Help :(
http status 404 The requested resource is not available.
Problem calling Servlet from jsp.
sendRedirect Problem