You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Mike Markovich <mi...@attbi.com> on 2002/09/29 18:53:11 UTC

How to deploy servlets in Tomcat?

Hi All,

I would really appreciate some help this... I am on an NT box with 
Tomcat 4.1.12.  My problem is that I am having trouble deploying 
servlets in Tomcat. Worse, I seem to go through this each time I upgrade 
to a new version of Tomcat.  Friday night I upgraded to version 4.1.12. 
Each time I upgrade I have problems getting simple servlets to execute - 
after a couple of hours of monkeying around my servlets suddenly ststart 
working.  I think I'm repeating the same steps over and over so I don't 
understand what I'm doing wrong and what I did right to make things 
work.  Which is frustrating because it means I'm not learning from the 
process. Please note, I can get the Tomcat servlet examples to execute 
so I'm pretty confident I have a good installation.  If I copy one of 
the examples, say "HelloWorldExample" to one of my directories it no 
longer works.

Here are the steps I am following to deploy a simple "Hello World" servlet::

1)  In webapps I create a directory named "hello".
2)  In "hello"  I create the "WEB-INF" directory.
3)  Inside the "WEB-INF" directory I place "web.xml".   (I'm not sure I 
need to do this...)
4)  I also add "classes" and "lib" directories under "WEB-INF".
5)  Under classes I create a directory name "hello".
6)  In "hello"  I place the my servlet "hello.HelloMike.class".  The 
name of the servlet is "HelloMike" and it resides in package "hello".
7)  I start Tomcat and attempt to browse to the servlet with the 
following url "http://localhost:8080/hello/servlet/hello.HelloMike"
8)  The browser returns the following:

HTTP Status 404 - /hello/servlet/hello.HelloMike
*type* Status report
*message* _/hello/servlet/hello.HelloMike_
*description* _The requested resource (/hello/servlet/hello.HelloMike) 
is not available._
Apache Tomcat/4.1.12

I'm really mystifyied as to what I am doing wrong and would greatly 
appreciate all insights and suggestions offerred.

Many thanks,
Mike




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: How to deploy servlets in Tomcat?

Posted by Jacob Kjome <ho...@visi.com>.
See comments inline...

At 05:35 PM 9/29/2002 -0700, you wrote:
>Hi Jacob and thanks for your response.
>
>I tried your suggestion regarding servlet mapping and it helped - I can 
>now execute servlets in the default package but I get the same message 
>when try to access a servlet that is not in the default package....oh
>yes Tomcat is shutdown while I deploy my servlets..

for servlets in packages, access them with the fully qualified package name 
such as:

http://localhost:8080/mycontext/servlet/com.mycompany.myapp.MyServlet


>As to a your point about buying some books etc.,...I will be the first to 
>agree with you that I don't know everything about Tomcat, but I want to 
>point out that I have spent a lot of time reading about servlets and 
>Tomcat from a vareity of sources.  Some books I have read include Jason 
>Hunter's Java Servlets (unfortunately, the first edition), James 
>Goodwill's Apache Jakarta-Tomcat from Apress (very recent),  David Harms, 
>JSP, Servlets, and MySQL, and Marty  Hall's Servlets and JavaServer 
>Pages.  So please be assured this is not a case of just firing off a 
>question to the list without doing some research first.

That's good.  Although, make sure you read the basics about deployment 
descriptors and you probably want to download the servlet spec pdf file 
from the java.sun.com site for reference.

>I agree with you that this is pretty basic stuff - and the books I 
>mentioned seem to outline it pretty well, but all the examples deploy
>to webapps/ROOT which is not what I am trying to do.  Even so, this is 
>pretty straight forward stuff  which is why it surprises and frustrates me 
>when something so simple becomes a road block.  So I posted my question in 
>hopes that someone would point out what I was doing wrong.

It is all the same anyway.  Whether you go from the root of the web or a 
named context on directory off the root, it is all the same.


>Lastly, do you know the in which version the default invoker was changed, 
>because I don't recall having to change conf/web.xml before.

Tomcat-4.0.5 and Tomcat-4.1.12 have the security fix applied.


>Again, thanks for your help,
>Mike
>
>
>
>Jacob Kjome wrote:
>
>>
>>The default servlet invoker was disabled by default for security reasons 
>>which is why you are getting a 404 error.  It can be re-enabled by 
>>uncommenting the mapping for the url pattern /servlet/* in 
>>$TOMCAT_HOME/conf/web.xml.  You will need to restart Tomcat after doing this.
>>
>><!--
>>     <servlet-mapping>
>>         <servlet-name>invoker</servlet-name>
>>         <url-pattern>/servlet/*</url-pattern>
>>     </servlet-mapping>
>>-->
>>
>>Also, when you talk about the steps you go through to deploy the servlet, 
>>Tomcat isn't currently running, is it?  The problem of Tomat running 
>>while you are doing these steps is that Tomcat auto-deploys webapps upon 
>>seeing a new directory or .war file in the webapps directory.  If you 
>>create a directory and then add all the other stuff underneath that, 
>>Tomcat will have attempted the deploy before everything is in place.  You 
>>should build the directory structure and then copy the whole finished 
>>thing to the webapps directory if you want to deploy stuff like that.
>>
>>As far as needing a web.xml file, this is pretty basic stuff.  Yes, you 
>>do. You really should buy a servlet book like Jason Hunter's Java Servlet 
>>Programming, 2nd edition.  Also, you can read the servlet spec on Sun's 
>>site.  It is apparent that you are attempting to use Tomcat without 
>>knowing what it is all about in the first place.  Taking a day to read up 
>>on servlets and then moving forward with Tomcat will be of immense 
>>benefit to you and remove a lot of frustration from the whole process.
>>
>>Jake
>>
>>At 09:53 AM 9/29/2002 -0700, you wrote:
>>
>>>Hi All,
>>>
>>>I would really appreciate some help this... I am on an NT box with 
>>>Tomcat 4.1.12.  My problem is that I am having trouble deploying 
>>>servlets in Tomcat. Worse, I seem to go through this each time I upgrade 
>>>to a new version of Tomcat.  Friday night I upgraded to version 4.1.12. 
>>>Each time I upgrade I have problems getting simple servlets to execute - 
>>>after a couple of hours of monkeying around my servlets suddenly ststart 
>>>working.  I think I'm repeating the same steps over and over so I don't 
>>>understand what I'm doing wrong and what I did right to make things 
>>>work.  Which is frustrating because it means I'm not learning from the 
>>>process. Please note, I can get the Tomcat servlet examples to execute 
>>>so I'm pretty confident I have a good installation.  If I copy one of 
>>>the examples, say "HelloWorldExample" to one of my directories it no 
>>>longer works.
>>>
>>>Here are the steps I am following to deploy a simple "Hello World" servlet::
>>>
>>>1)  In webapps I create a directory named "hello".
>>>2)  In "hello"  I create the "WEB-INF" directory.
>>>3)  Inside the "WEB-INF" directory I place "web.xml".   (I'm not sure I 
>>>need to do this...)
>>>4)  I also add "classes" and "lib" directories under "WEB-INF".
>>>5)  Under classes I create a directory name "hello".
>>>6)  In "hello"  I place the my servlet "hello.HelloMike.class".  The 
>>>name of the servlet is "HelloMike" and it resides in package "hello".
>>>7)  I start Tomcat and attempt to browse to the servlet with the 
>>>following url "http://localhost:8080/hello/servlet/hello.HelloMike"
>>>8)  The browser returns the following:
>>>
>>>HTTP Status 404 - /hello/servlet/hello.HelloMike
>>>*type* Status report
>>>*message* _/hello/servlet/hello.HelloMike_
>>>*description* _The requested resource (/hello/servlet/hello.HelloMike) 
>>>is not available._
>>>Apache Tomcat/4.1.12
>>>
>>>I'm really mystifyied as to what I am doing wrong and would greatly 
>>>appreciate all insights and suggestions offerred.
>>>
>>>Many thanks,
>>>Mike
>>>
>>>
>>>
>>>
>>>--
>>>To unsubscribe, e-mail:
>>><ma...@jakarta.apache.org>
>>>For additional commands, e-mail: 
>>><ma...@jakarta.apache.org>
>>
>
>
>
>
>--
>To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
>For additional commands, e-mail: <ma...@jakarta.apache.org>

Re: How to deploy servlets in Tomcat?

Posted by Mike Markovich <mi...@attbi.com>.
Hi Jacob and thanks for your response.

I tried your suggestion regarding servlet mapping and it helped - I can 
now execute servlets in the default package but I get the same message 
when try to access a servlet that is not in the default package....oh  
yes Tomcat is shutdown while I deploy my servlets..

As to a your point about buying some books etc.,...I will be the first 
to agree with you that I don't know everything about Tomcat, but I want 
to point out that I have spent a lot of time reading about servlets and 
Tomcat from a vareity of sources.  Some books I have read include Jason 
Hunter's Java Servlets (unfortunately, the first edition), James 
Goodwill's Apache Jakarta-Tomcat from Apress (very recent),  David 
Harms, JSP, Servlets, and MySQL, and Marty  Hall's Servlets and 
JavaServer Pages.  So please be assured this is not a case of just 
firing off a question to the list without doing some research first.  

I agree with you that this is pretty basic stuff - and the books I 
mentioned seem to outline it pretty well, but all the examples deploy  
to webapps/ROOT which is not what I am trying to do.  Even so, this is 
pretty straight forward stuff  which is why it surprises and frustrates 
me when something so simple becomes a road block.  So I posted my 
question in hopes that someone would point out what I was doing wrong.

Lastly, do you know the in which version the default invoker was 
changed, because I don't recall having to change conf/web.xml before.

Again, thanks for your help,
Mike



Jacob Kjome wrote:

>
> The default servlet invoker was disabled by default for security 
> reasons which is why you are getting a 404 error.  It can be 
> re-enabled by uncommenting the mapping for the url pattern /servlet/* 
> in $TOMCAT_HOME/conf/web.xml.  You will need to restart Tomcat after 
> doing this.
>
> <!--
>     <servlet-mapping>
>         <servlet-name>invoker</servlet-name>
>         <url-pattern>/servlet/*</url-pattern>
>     </servlet-mapping>
> -->
>
> Also, when you talk about the steps you go through to deploy the 
> servlet, Tomcat isn't currently running, is it?  The problem of Tomat 
> running while you are doing these steps is that Tomcat auto-deploys 
> webapps upon seeing a new directory or .war file in the webapps 
> directory.  If you create a directory and then add all the other stuff 
> underneath that, Tomcat will have attempted the deploy before 
> everything is in place.  You should build the directory structure and 
> then copy the whole finished thing to the webapps directory if you 
> want to deploy stuff like that.
>
> As far as needing a web.xml file, this is pretty basic stuff.  Yes, 
> you do. You really should buy a servlet book like Jason Hunter's Java 
> Servlet Programming, 2nd edition.  Also, you can read the servlet spec 
> on Sun's site.  It is apparent that you are attempting to use Tomcat 
> without knowing what it is all about in the first place.  Taking a day 
> to read up on servlets and then moving forward with Tomcat will be of 
> immense benefit to you and remove a lot of frustration from the whole 
> process.
>
> Jake
>
> At 09:53 AM 9/29/2002 -0700, you wrote:
>
>> Hi All,
>>
>> I would really appreciate some help this... I am on an NT box with 
>> Tomcat 4.1.12.  My problem is that I am having trouble deploying 
>> servlets in Tomcat. Worse, I seem to go through this each time I 
>> upgrade to a new version of Tomcat.  Friday night I upgraded to 
>> version 4.1.12. Each time I upgrade I have problems getting simple 
>> servlets to execute - after a couple of hours of monkeying around my 
>> servlets suddenly ststart working.  I think I'm repeating the same 
>> steps over and over so I don't understand what I'm doing wrong and 
>> what I did right to make things work.  Which is frustrating because 
>> it means I'm not learning from the process. Please note, I can get 
>> the Tomcat servlet examples to execute so I'm pretty confident I have 
>> a good installation.  If I copy one of the examples, say 
>> "HelloWorldExample" to one of my directories it no longer works.
>>
>> Here are the steps I am following to deploy a simple "Hello World" 
>> servlet::
>>
>> 1)  In webapps I create a directory named "hello".
>> 2)  In "hello"  I create the "WEB-INF" directory.
>> 3)  Inside the "WEB-INF" directory I place "web.xml".   (I'm not sure 
>> I need to do this...)
>> 4)  I also add "classes" and "lib" directories under "WEB-INF".
>> 5)  Under classes I create a directory name "hello".
>> 6)  In "hello"  I place the my servlet "hello.HelloMike.class".  The 
>> name of the servlet is "HelloMike" and it resides in package "hello".
>> 7)  I start Tomcat and attempt to browse to the servlet with the 
>> following url "http://localhost:8080/hello/servlet/hello.HelloMike"
>> 8)  The browser returns the following:
>>
>> HTTP Status 404 - /hello/servlet/hello.HelloMike
>> *type* Status report
>> *message* _/hello/servlet/hello.HelloMike_
>> *description* _The requested resource 
>> (/hello/servlet/hello.HelloMike) is not available._
>> Apache Tomcat/4.1.12
>>
>> I'm really mystifyied as to what I am doing wrong and would greatly 
>> appreciate all insights and suggestions offerred.
>>
>> Many thanks,
>> Mike
>>
>>
>>
>>
>> -- 
>> To unsubscribe, e-mail:   
>> <ma...@jakarta.apache.org>
>> For additional commands, e-mail: 
>> <ma...@jakarta.apache.org>
>
>




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: How to deploy servlets in Tomcat?

Posted by Jacob Kjome <ho...@visi.com>.
The default servlet invoker was disabled by default for security reasons 
which is why you are getting a 404 error.  It can be re-enabled by 
uncommenting the mapping for the url pattern /servlet/* in 
$TOMCAT_HOME/conf/web.xml.  You will need to restart Tomcat after doing this.

<!--
     <servlet-mapping>
         <servlet-name>invoker</servlet-name>
         <url-pattern>/servlet/*</url-pattern>
     </servlet-mapping>
-->

Also, when you talk about the steps you go through to deploy the servlet, 
Tomcat isn't currently running, is it?  The problem of Tomat running while 
you are doing these steps is that Tomcat auto-deploys webapps upon seeing a 
new directory or .war file in the webapps directory.  If you create a 
directory and then add all the other stuff underneath that, Tomcat will 
have attempted the deploy before everything is in place.  You should build 
the directory structure and then copy the whole finished thing to the 
webapps directory if you want to deploy stuff like that.

As far as needing a web.xml file, this is pretty basic stuff.  Yes, you do. 
You really should buy a servlet book like Jason Hunter's Java Servlet 
Programming, 2nd edition.  Also, you can read the servlet spec on Sun's 
site.  It is apparent that you are attempting to use Tomcat without knowing 
what it is all about in the first place.  Taking a day to read up on 
servlets and then moving forward with Tomcat will be of immense benefit to 
you and remove a lot of frustration from the whole process.

Jake

At 09:53 AM 9/29/2002 -0700, you wrote:
>Hi All,
>
>I would really appreciate some help this... I am on an NT box with Tomcat 
>4.1.12.  My problem is that I am having trouble deploying servlets in 
>Tomcat. Worse, I seem to go through this each time I upgrade to a new 
>version of Tomcat.  Friday night I upgraded to version 4.1.12. Each time I 
>upgrade I have problems getting simple servlets to execute - after a 
>couple of hours of monkeying around my servlets suddenly ststart 
>working.  I think I'm repeating the same steps over and over so I don't 
>understand what I'm doing wrong and what I did right to make things 
>work.  Which is frustrating because it means I'm not learning from the 
>process. Please note, I can get the Tomcat servlet examples to execute so 
>I'm pretty confident I have a good installation.  If I copy one of the 
>examples, say "HelloWorldExample" to one of my directories it no longer works.
>
>Here are the steps I am following to deploy a simple "Hello World" servlet::
>
>1)  In webapps I create a directory named "hello".
>2)  In "hello"  I create the "WEB-INF" directory.
>3)  Inside the "WEB-INF" directory I place "web.xml".   (I'm not sure I 
>need to do this...)
>4)  I also add "classes" and "lib" directories under "WEB-INF".
>5)  Under classes I create a directory name "hello".
>6)  In "hello"  I place the my servlet "hello.HelloMike.class".  The name 
>of the servlet is "HelloMike" and it resides in package "hello".
>7)  I start Tomcat and attempt to browse to the servlet with the following 
>url "http://localhost:8080/hello/servlet/hello.HelloMike"
>8)  The browser returns the following:
>
>HTTP Status 404 - /hello/servlet/hello.HelloMike
>*type* Status report
>*message* _/hello/servlet/hello.HelloMike_
>*description* _The requested resource (/hello/servlet/hello.HelloMike) is 
>not available._
>Apache Tomcat/4.1.12
>
>I'm really mystifyied as to what I am doing wrong and would greatly 
>appreciate all insights and suggestions offerred.
>
>Many thanks,
>Mike
>
>
>
>
>--
>To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
>For additional commands, e-mail: <ma...@jakarta.apache.org>