This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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. Thanks Mark
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.
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. Mark
Where did you create the classes subdirectory? It should go under the WEB-INF directory of the webapp: mywebapp-root/WEB-INF/classes You can also jar up your classes into a library if you would like and place them in the lib directory: mywebapp-root/WEB-INF/lib 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.