aspose file tools*
The moose likes Tomcat and the fly likes Servlet Deployment Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Servlet Deployment" Watch "Servlet Deployment" New topic
Author

Servlet Deployment

Padma Priya
Ranch Hand

Joined: Feb 01, 2007
Posts: 113
hi Everyone,

I am having a problem with deploying my servlet.This is my first servlet example.Can anyone help me out.

my java source code is

package test;

import java.io.*;

import javax.servlet.http.*;
import javax.servlet.*;

public class HelloWorldServlet extends HttpServlet
{
public void service(HttpServletRequest req,HttpServletResponse res)throws ServletException, IOException
{
PrintWriter out = res.getWriter();

System.out.println("Hello, world!");
//out.close();
}
}



My web.xml is as follows

<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">

<display-name>Tomcat Documentation</display-name>
<description>
Tomcat Documentation.
</description>

<servlet>
<servlet-name>one</servlet-name>
<servlet-class>test.HelloWorldServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>one</servlet-name>
<url-pattern>/one</url-pattern>
</servlet-mapping>

</web-app>


My directory stucture is

CATALINA_HOME/webapps/MyFirstWebApp/WEB-INF/classes/test/HelloWorldServlet.class

and of course i have placed web.xml under the WEB-INF directory

Can anyone tell me where i have gone wrong

Thanks in advance
Deepthi
Rancy Chadha
Ranch Hand

Joined: Jul 12, 2006
Posts: 135
Hi Deepthi,
I tried the code on my system and I am using tomcat ver 5.0 and it worked just fine for me.Which server are you using?Could you elaborate on what exactly is happening. Are you getting some error message like 404(resource not found)?I will tell you what I have done, probably you can try this as well. I made a html page and I put a submit button there clicking on which it will call my servlet(one that you have coded) and will display a message. Only change that I have done in your servlet code is: instead of System.out.println("message") I have put out.println("message") so that I get the output on my page. Your directly structure looks fine and your deployment descriptor is also fine. If you elaborate on the exact issue you are facing while deployment we will be able to resolve it.
Thanks,
Rancy


Thanks,<br />-Rancy
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Rancy Chadha's advice is good.

If his fix doesn't work for you, when posting back be sure to also include the URL that you are using when trying to access your servlet.

As a side note, overriding the service method is almost never a good idea.
You should, instead, override the doGet method or, if handling form submissions, override the doPost method. The service method, if left alone, will route the request to the proper one for you. This isn't going to fix this problem but it's best to start out on the right foot and avoid bad practices.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Muhammad Saifuddin
Ranch Hand

Joined: Dec 06, 2005
Posts: 1321

Originally posted by Deepthi Tirunahari:

I am having a problem with deploying my servlet.


check your server log and find out what error/Exception you got after calling this servlet.. paste it here the stake trace it would help us to find if there got any other problem..


Saifuddin..
[Blog][Linkedin] How To Ask Questions On JavaRanch My OpenSource
Padma Priya
Ranch Hand

Joined: Feb 01, 2007
Posts: 113
Hi Everyone,

Thanks a lot for your valuable advice....

The version of tomcat i using is 5.5.20

In the browser when i give

http://localhost:8080/manager/html

The page is getting displayed fine.....But when i try to click on the MyFirstWebApp on that page i get the following error report

HTTP Status 404 - /MyFirstWebApp/

---------------------------------------------------------------------------
type : Status report

message : /MyFirstWebApp/

description : The requested resource (/MyFirstWebApp/) is not available.


---------------------------------------------------------------------------

Apache Tomcat/5.5.20




Can anyone tell me what might be the reason for this error
Rancy Chadha
Ranch Hand

Joined: Jul 12, 2006
Posts: 135
Hi Deepthi,

The reason I think you are unable to deploy the servlet would be because you have put your servlet directory under webapps directory and you are using tomcat ver 5.5 so I think instead of putting your servlet directory(MyFirstWebApp) under webapps, try putting it under webapps/ROOT directory. Again I am not sure if this will work for you or not but give it a try and also I would like to tell you where I found this, refer to this link Click Here. This is a Tutorial on Installing and Using
Jakarta Tomcat 5.5 for Servlet and JSP Development. Since I have 5.0 installed I cannot test, you can try and let me know about it.

Thanks,
Rancy
Raghavendra Nittur
Greenhorn

Joined: Feb 19, 2007
Posts: 29
hi Deepthi,
try
http://localhost:8080/MyFirstWebApp/one

as i noticed, your web.xml has url-pattern as "/one".

Regards, Raghav
Padma Priya
Ranch Hand

Joined: Feb 01, 2007
Posts: 113
hi Rancy,

I am just not able to deploy my web applications on tomcat 5.5.....I have read through the link that you have given me....but nothing just seems to work out....

But on my tomcat 5.0 i am able to deploy my applications very easily....It is just that i am having a problem with tomcat 5.5...

can anybody please help me out...

I keep getting this message

HTTP Status 404 - /MyFirstWebApp/HelloWorldServlet

--------------------------------------------------------------------------------

type Status report

message /MyFistWebApp/one
description The requested resource (/MyFistWebApp/one
) is not available.


--------------------------------------------------------------------------------

Thanks inAdvance
Deepthi

Apache Tomcat/5.5.20
Rancy Chadha
Ranch Hand

Joined: Jul 12, 2006
Posts: 135
Alright Deepthi, don't worry, what I'll do is I'll install ver 5.5 on my system and lets see if it works or not, okay.
I will reply to you as soon as I work on it.

Thanks,
Rancy
Padma Priya
Ranch Hand

Joined: Feb 01, 2007
Posts: 113
hi Rancy,

Thanks a lot for your help and support........

Regards
Deepthi
Rancy Chadha
Ranch Hand

Joined: Jul 12, 2006
Posts: 135
Hi Deepthi,

I did install ver 5.5 on my system and tried the same thing on it and it works fine for me. Here is step wise procedure for what I have done:

1)The directory which is the source directory "MyFirstWebApp" is under "WebApps" folder
2)Under MyFirstWebApp I have one html file called "test.html" which is the interface that uses my servlet to display a message and a folder WEB-INF folder
3)Under Web-Inf folder I have a "classes" folder which contains the class file of my servlet that is "HelloWorldServlet.class"
4)This folder also contains "web.xml" file which is same as yours.

I am using port 8383 for this version so when I type "http://localhost:8383/MyFirstWebApp/test.html" I get my page and I also get the correct output.
Also when I want to directly communicate with the servlet and I type "http://localhost:8383/MyFirstWebApp/one" I get the output.

Probably like Raghav said, instead of using path "http://localhost:8080/MyFirstWebApp/HelloWorldServlet" try using the link "http://locatlhost:8080/MyFirstWebApp/one" because you have mapped your servlet with this name "/one" in your deployment descriptor and it should give you the output. It works absolutely fine for me. Do let me know the result

Thanks,
Rancy
Padma Priya
Ranch Hand

Joined: Feb 01, 2007
Posts: 113
hi Rancy,

It Worked!!!

I have followed the step by step procedure you have given me......i started everything from scratch.....i did the same steps i did before and it worked fine for me..........And i feel very guilty for wasting your time with such a simple installation......sorry for that

And Thnks a lot

Regards
Deepthi
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Servlet Deployment