October 8th, 2002, 10:53 PM
Problem deploying a servlet
I just start on Servlet programming....
I used the default configuration from tomcat 4.1. I placed the servlet in the %catalina%/webapps/examples/WEB-INF/clases/ and it is working with http://localhost:8000/examples/servlet/MyServlet.
However, I want to put the servlet under my own app directory for example called myApp. Then I put the class file in %catalina%/webapps/myApp/WEB-INF/classes/. But then it give an 404 error saying the requested source is not available when I try to access it using http://localhost:8000/myApp/servlet/MyServlet.
I had check the <Context> tag in the %catalina%/conf/server.xml and found that the host is set to the following:-
<Host name="localhost" debug="0" appBase="webapps"
Where the autoDeploy is set to true.
So, why is that I still can't access the http://localhost:8000/myApp/servlet/MyServlet ?
October 8th, 2002, 11:24 PM
autoDeploy is only for .war files.
You need to create a new <Context> tag for your myApp directory. Just copy the tag for the examples context and modify appropriately.
October 9th, 2002, 12:04 AM
Thanks for your reply.
I had just tested with the following :-
<!-- myApp Context -->
<Context path="/myApp" docBase="myApp" debug="0"
<Environment name="maxExemptions" type="java.lang.Integer"
I added the above directly below the <Context> for examples before the closing </host>. Anyway it doesn't work for me. Am I missing something here ?
Thanks for the help.
October 9th, 2002, 11:30 AM
It looks right to me. Try setting debug to 1 and seeing if you get any errors.
October 9th, 2002, 11:50 AM
No.. there is no error message.
The funny thing is if I place a file say index.htm in %catalina%/webapps/myApp/index.htm
The page work fine. The only thing is that the servlet cann't be found... It only give me a HTTP Status 404 with error :-
The requested resource (/myApp/servlet/MyServlet) is not available.
How do u think ?
October 9th, 2002, 01:04 PM
Well, here's simplified <Context> tag:
Make sure your servlet is in
<Context path="/myApp" docBase="myApp" debug="0" reloadable="true"/>
it's case sensitive, so double check.
October 9th, 2002, 01:45 PM
i'm a novice j2ee guy...
is the servlet directory automatically mapped to that application?
or do you specify this in web.xml??
i apologize if this is way off, and if i don't know what i'm talking about.. (i'm just learning)
October 9th, 2002, 02:00 PM
It should be automatically mapped.
October 9th, 2002, 10:51 PM
I read in the books from New Riders.. the author say that the servlet should be deploy automatically if we put it under
We don't even need to set a <context> tag in
But, what happen to me that even if I set a <content> tag, it will not deploy also.
I have doubled check and double checked again and again and tested both in my office pc and home pc. Both carry exactly the same configuration and code.
I even copy the %catalina%/webapps/examples to rename it to myApp ... it's not working as well.
Any suggestion ?
October 10th, 2002, 02:22 AM
Well, I ran the problem down, but... I'm really confused now .
Open your conf/web.xml file and look for the following lines:
remove the comments around those and everything should work fine.
My only question is, why was it commented out in the first place? In the examples folder they create a filter and a filter-mapping that maps the invoker servlet to servlet/*, so maybe that's the way they want it done now. I can't find anything in the documentation, though.
Oh, and you where right about not needing to fiddle with the server.xml file. It should automatically find any apps you put into the webapps folder.
October 10th, 2002, 02:32 AM
You did it It's working now ... hehehe...
I'm so happy now :-D
February 9th, 2003, 11:29 PM
Bricker42 you rock!
Nguip I must be using the same book as you. I had this exact problem.
I did what you said Bricker42 and it worked. It seems very odd that that block of code would be commented out. Anyone know if using filters is the recomended way to deploy servlets now???
February 10th, 2003, 01:51 AM
I thought I posted back here to answer that. Oh well .
Yes, filters are the recommended way to deploy a directory of servlets now. I guess there were some security concerns with using the old way.
From what I've read, though, the *best practices* way to deploy servlets is to give each its own mapping in your deployment descriptor (web.xml).