aspose file tools*
The moose likes Servlets and the fly likes Newbie: get tomcat run helloworld Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Newbie: get tomcat run helloworld" Watch "Newbie: get tomcat run helloworld" New topic
Author

Newbie: get tomcat run helloworld

Andy Zhu
Ranch Hand

Joined: May 26, 2004
Posts: 145
1. installed tomcat (no web server) 5.0.25 prebuilt, as a service on xp. running the example has no problem. And, if I put my DynamicPage.class in servlet example and modify its web.xml, no problem.

Only when it is located in webapps/WEB-INF/class and with following web.xml:

<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">

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

when run: http://localhost:8080/hello or http://localhost:8080/DynamicPage, neither works:
error 404. page is not available.

Noticed that, in my server.xml, I don't have any Context element. Is this relevant? need your help to get it run.

Thanks


--------<br />Andy Zhu<br />scjp 1.4<br />scjd 1.4<br />SAS Certified Programmer 9.0
Sebastian Green
Ranch Hand

Joined: Jan 30, 2004
Posts: 136
Dont really shure but in "webapps" there have to be a folder which you place your servlet in. If you type http://localhost:8080/hello. Then tomcat will be looking in the webapps/ROOT-folder. So try to add a new folder "helloap" then the url will be http://localhost:8080/helloap/hello

Hope this help!
[ June 03, 2004: Message edited by: Sebastian Green ]

/ Sebastian<br />No blog, No homepage, No life?
Jon Entwistle
Ranch Hand

Joined: Feb 20, 2003
Posts: 118
Hi - I second what Sebastian is saying. Each application has a seperate folder in webapps. ROOT is the default application folder and is accessed through locahost:8080.

You need to mirror the structure of root in your new application folder, e.g.

/webapps/myapp/WEB-INF/web.xml for the configuration file

and

/webapps/myapp/WEB-INF/classes for your class files

etc.

Cheers,

Jon


SCJD, SCEA
Andy Zhu
Ranch Hand

Joined: May 26, 2004
Posts: 145
Thanks, Sebastian and Jon. I did have a sub folder for DynamicPage. The structure is:

%CATALINA_HOME%/webapps/test/WEB-INF/class/DynamicPage.class

1. I tried to put various values in <servlet-class> element, such as test.WEB-INF.class.DynamicPage, but out of luck.
2. Even a simple static html in webapps won't be able to display by tomcat.
3. So I think the problem may not be in web.xml, rather in server.xml, which I didn't touch after installation. I checked various resource saying I should modify a comment-out <Context> and <DefaultContext> in conf/server.xml, but in my installed server.xml I can't find such an element anywhere. So I guess tomcat won't be able to recognize webapps. However, I don't know how to add <Context> stuff. Or my logic is completely wrong. Please, help me.
Jon Entwistle
Ranch Hand

Joined: Feb 20, 2003
Posts: 118
Hi Andy,

You do not need to touvh the server.xml - If you send me a tar or zip file with your webapp/yourapp folder, I will take a look.

Send it to entwistle@euskalnet.net

Cheers,

Jon
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12806
    
    5
<servlet-name>DynamicPage</servlet-name>
<servlet-class>DynamicPage</servlet-name>

Man! I get tired of saying this - don't you people ever read other posts in this forum to see if they might apply to you?
Do NOT leave your servlet class in the default package - ALL classes used in servlets and JSP should be put in a package.
If you create your own directory, Tomcat will NOT recognize it as an application unless there is a WEB-INF directory having a minimal web.xml file.
Also - Look at how the examples web.inf is used.
Finally - download the servlet API from Sun's web site. wherein are laid out all of the requirements for running servlets.
Bill
Andy Zhu
Ranch Hand

Joined: May 26, 2004
Posts: 145
Hi, Jon:

Thank you very much. I sent you email with my tar attachment. Thanks for checking my program.
Jon Entwistle
Ranch Hand

Joined: Feb 20, 2003
Posts: 118
Hi Andy,

You had a couple of problems:


<servlet-class>DynamicPage</servlet-name>


- Is this a servlet-class tag or a servlet-name tag?


<url-pattern>hello</url-pattern>


- You need to preface hello with a slash: /hello


On tomcat, the first place to look to debug when you have problems like these is $CATALINA_HOME/logs/catalina.out

The other log files in this folder log whatever you set them to in your config files - by default stack traces of exceptions which reach the container.

Cheers,

Jon
Andy Zhu
Ranch Hand

Joined: May 26, 2004
Posts: 145
Hey, Jon:

Thank you very much. It is the tag problem. Now, I am on my way doing business. Shame of myself.
 
Don't get me started about those stupid light bulbs.
 
subject: Newbie: get tomcat run helloworld