• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Deploying Servlet in Tomcat 5.0

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am trying to deploy a simple servlet on Tomcat 5.0
I am getting an error stating the requested resource is not available.

I am placing the Hello World class file in Tomcat 5.0\webapps\onjava\WEB-INF\classes where onjava is the package which I have kept in the webapps directory.
I have changed the server.xml file to include
<Context path="/onjava" docBase="onjava" debug="0" reloadable="true" />

I can run a jsp but when I am trying to run the servlet it gives an error.

Here is the web.xml file
<web-app>
<servlet>

<servlet-name>HelloWorld</servlet-name>
<servlet-class>HelloWorld</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloWorld</servlet-name>
<url-pattern>/HelloWorld</url-pattern>
</servlet-mapping>
</web-app>

Thanks a lot to all...
 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi I am facing the same problem can anyone help with this stuff
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are getting a 404 /requested resource not avail. that means u haven't setup up ur app right. Did u restart tomcat after u edited ur server.xml file?
 
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Arian,

I have changed the server.xml file to include
<Context path="/onjava" docBase="onjava" debug="0" reloadable="true" />

Could you temporarily comment out this line?

I can run a jsp but when I am trying to run the servlet it gives an error.
Did you provide this url when running the servlet: http://localhost:8080/onjava/HelloWorld ?

Your web.xml looks ok.

Just to make sure your Tomcat setup is ok, could you execute the Tomcat servlet examples: http://localhost:8080/servlets-examples/ ?

Joyce
 
adrian mills
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi joyce
I checked the servlet-examples they are working properly.No problem with them.

In the server.xml file I have made the following entry..
<Context path="/myproject" docBase="myproject" debug="0" reloadable="true" />

Is there any other entry needed in the server.xml for running servlets.
I can run my JSP's without any problem...


Thanks for all u r help in advance
 
adrian mills
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi joyce I tried commenting the entry in server.xml as well as typing the path in the url.
It does not work.Can u friends give me some sample entry with from ur side
which I can use as reference.
Please mention the directory structure also.
I think I am going wrong in the mappings in web.xml or server.xml.
Can u please give me same sample entries.
Thanks a lot for all u r help
 
Joyce Lee
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Adrian,

<Context path="/myproject" docBase="myproject" debug="0" reloadable="true" />
First, comment this statement to narrow down the problem.

Create a directory/file structure as follows:



The web.xml has the following contents:


Compile HelloWorldServlet.java and place the *.class file under classes directory.


After restarting the Tomcat server, run this url: http://localhost:8080/myproject/HelloWorld on a browser.

Joyce
 
Joyce Lee
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You might want to take a look at A Tutorial on Installing and Using Tomcat 4 or 5 for Servlet and JSP Development.
 
adrian mills
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi joyce
I did the stuff which u had asked me to do as per u r reply.
I get an error stating
The requested resource (/myprject/HelloWorld) is not available

I have commented the entry in server.xml also.

I am working with Tomcat 5.0.14 and have installed Tomcat on
C:\Tomcat5.0 directory on windows 2000 client.
I have not added anything to the classpath.

I am unable to understand what the real problem is.
I have worked with Tomcat 4.0 and this would have worked in it I know that.

Is there any problem with Tomcat5.0.14.

I also checked the link which u have sent in your reply.
It tells us the same method.
Except that we need to add the servlet mapping which is cumpolsory from Tomcat 5.0 onwards.
 
adrian mills
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also Joyce if I give a System.out.println in my servlet where will i see it
On which console will it get printed?
Like in Tomcat4.0 we could view it on the console of Tomcat server.
Does it come on the open console monitor.
Plz tell me if u have any idea.
And thanks a ton for u r help buddy.
 
adrian mills
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have set my class path for win2000 client as follows
CLASSPATH= C:\Tomcat 5.0\common\lib\servlet-api.jar;C:\Tomcat 5.0\common\lib\jsp-api.jar

I think I had mentioned that i had not set class path but I have that was a mistake.I am sorry
 
Joyce Lee
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Adrian, did you restart the server after you made the changes?

According to your previous post, you said that the servlet-examples were working fine. Did you execute each servlet example? Could you create a new directory, say test, under webapps and copy everything under servlet-examples into this new directory? Then run this url: http://localhost:8080/test/ ? It should be working since it's identical to servlet-examples.

It tells us the same method.
Except that we need to add the servlet mapping which is cumpolsory from Tomcat 5.0 onwards.

You can try uncomment the Invoker as mentioned in the Tutorial and run this url: http://localhost:8080/myproject/servlet/HelloWorldServlet .

Also Joyce if I give a System.out.println in my servlet where will i see it On which console will it get printed?
Like in Tomcat4.0 we could view it on the console of Tomcat server.
Does it come on the open console monitor.

Yes, when starting the Tomcat 5 server, it opens a console monitor as in Tomcat 4.0. The output of System.out.println will be printed on the console.

FYI, I'm using win2000 and Tomcat 5.0.28.
 
adrian mills
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ya joyce I have restarted the server everytime I have made any changes.
I put a new directory test.Copied everything from servlet-examples into it
It is working fine.

Ya I uncommented the invoker servlet and now it is working fine.
But why do I need to do this.
Cant it be done without it.
I am really glad that u have helped me a lot
Thanks a lot joyce.I am going to try deploying struts example on this and might need u r help ..
I am really happy.. but can u tell me how we will comment the invoker servlet tag in web.xml and they deploy our servlets.
 
Joyce Lee
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ya I uncommented the invoker servlet and now it is working fine.
But why do I need to do this.
Cant it be done without it.

Actually, it's not necessary to uncomment the invoker if proper <server-mapping> is provided in myproject\WEB-INF\web.xml. You managed to run the servlet-examples without uncommenting the invoker initially. That is because proper <servlet-mapping> is provided for each servlet in servlet-examples\WEB-INF\web.xml.

You can read more about Invoker here.
 
adrian mills
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi joyce,
I tried to comment the invoker servelet tag in Tomcat server conf directory and my application does not work.
U had mentioned that I was not mapping the servlet correctly if it works alright when the invoker servlet tag is
not commented.

I am copying my web.xml as follows
<web-app>
<servlet>
<servlet-name>Login</servlet-name>
<servlet-class>com.cspl.intranet.user.Login</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Login</servlet-name>
<url-pattern>/myproject/jsp/Login</url-pattern>
</servlet-mapping>
</web-app>

In the jsp on click of the button I have given action as follows:
<Form name="Login" method="get" action="Login">

My jsp is in the following folder.
C:\Tomcat 5.0\webapps\myproject\jsp

I have kept the class file in the following folder
C:\Tomcat 5.0\webapps\myproject\WEB-INF\classes\com\cspl\intranet\user

Do u think there is something wrong in the mapping
 
Joyce Lee
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Adrian,

<url-pattern>/myproject/jsp/Login</url-pattern>
...
C:\Tomcat 5.0\webapps\myproject\jsp


Based on the above url-pattern and the location of the jsp file, try the following form's action:



You can find out more about mapping in the Servlet specification. The latest version is 2.4 which can be downloaded here.
[ December 15, 2004: Message edited by: Joyce Lee ]
 
adrian mills
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Joycee thanks a lot that worked.
It nice now I can do some more things on it.

Btw I have given some system.out.println in my servlete but they are not getting printed on the console.
Do u know where can I find them.
Also presently while starting tomcat I have to go to Start->Apache Tomcat5.0->Start Tomcat option.
I get a small window which is displayed till the server is started.How can I avoid this can u help me on this.

Also i am very grateful to you for helping me out with this.Bcause I know u might feel that what a childish mistake
I am doing but it is only the first time i am working with Tomcat.Earlier I was working with a preconfigured Tomcat.
Thanks a lot for u help..
Looking forward for more discussions with u..

 
Joyce Lee
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Glad that it worked.

Also presently while starting tomcat I have to go to Start->Apache Tomcat5.0->Start Tomcat option.
I get a small window which is displayed till the server is started.How can I avoid this can u help me on this.


I bet you installed the Tomcat using the .exe version. I downloaded the .zip version. So when I want to start the Tomcat server, I run the startup.bat in Tomcat\bin manually. Once the startup.bat is executed, a dos window (on windows) will be popped up and it shows the status of the Tomcat server. It'll be automatically removed when you shutdown (shutdown.bat) the server. The output of System.out.println is printed on this pop-up window.

Bcause I know u might feel that what a childish mistake
I have never felt that way towards you.
 
adrian mills
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh sorry dont feel disturbed.
I have seen many experienced professionals getting irritated when someone does some silly mistake.Nways if you have not felt that way I am very happy.
Good to know that,I am a bit relaxed .
I have installed Tomcat from a developerIQ CD.U are right it is an exe.
Is there any way I can do it the way u are doing it with my current installation..
Hey joyce and have u worked with Ant??
I have posted a query on the Ant forum..If u have any idea please tell me..
Once again thanks a lot glad to have an experienced online friend like u who is ready to help.thanks a lot.
 
Joyce Lee
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have installed Tomcat from a developerIQ CD.U are right it is an exe.
Is there any way I can do it the way u are doing it with my current installation..


Instead of clicking on the Start->Apache Tomcat5.0->Start Tomcat option, you can launch the Tomcat server by executing the startup.bat under Tomcat\bin.

You can also download the latest or other version of Tomcat here. As mentioned earlier, I downloaded Tomcat 5.0.28.zip. Do not use the alpha or beta version since it's not stable.
 
adrian mills
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Joyce
I tried the to go to Tomcat\bin and run startup.bat but the window just gets closed seems there is some problem.
I dont get any print on the window the window just closes on its own
 
Joyce Lee
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I tried the to go to Tomcat\bin and run startup.bat but the window just gets closed seems there is some problem.
I dont get any print on the window the window just closes on its own



Could it be the Tomcat server already running when you executed the startup.bat? Did you install the Tomcat as a service? You can go to these two places to check if the Tomcat server is already running.

1. Task Manager
2. Start->Administrative Tools->Services. Look for Apache Tomcat.
[ December 16, 2004: Message edited by: Joyce Lee ]
 
adrian mills
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ya it is in Services.
But the startup option is manual so unless I start tomcat it will not be running.
I also checked when I executed the startup.bat command Tomcat was not on.
 
Joyce Lee
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

But the startup option is manual so unless I start tomcat it will not be running.
I also checked when I executed the startup.bat command Tomcat was not on.



In that case, I've no idea. On my the other machine, I installed Tomcat 5.0.28.exe version. With the service off, I've no problem running the startup.bat.
reply
    Bookmark Topic Watch Topic
  • New Topic