• Post Reply Bookmark Topic Watch Topic
  • New Topic

Servlet Package question of mine.  RSS feed

 
ranger
Sheriff
Posts: 17314
11
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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>.
 
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
ranger
Sheriff
Posts: 17314
11
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Author
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Mark Spritzler
ranger
Sheriff
Posts: 17314
11
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Mark
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!