tags:

views:

70

answers:

5

Hi!

I have put my project in tomcat_home/webapps/ directory. The structure is : project_name/WEB-INF/classes. in WEB-INF i have put my web.xml descriptor. The problem is that when i try to run the application, it doesn't find the files. The error is:

The requested resource () is not available.

My web.xml content is:

<?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">
<servlet>
   <servlet-name>Chapter1 Servlet</servlet-name>
   <servlet-class>Ch1Servlet</servlet-class>
</servlet>

<servlet-mapping>
   <servlet-name>Chapter1 Servlet</servlet-name>
   <servlet-url>/Serv1</servlet-url> 
</servlet-mapping>
</web-app>

I have also restarted the server, but it doesn't want to work. Any suggestions?

A: 

If you are using the default server.xml that comes with Tomcat, you should not have to alter it to just get your Web app running. Have you tried accessing it from the following URL: http://localhost:8080/project_name/

Chris J
yes, but doesn't work
artaxerxe
+1  A: 

Does your servlet have a namespace. In the tag you need to fully qualify the Ch1Servlet class, i.e. my.code.Ch1Servlet

--- Additional after reading comments -----

Ok, try this. Create a context for your webapp. Create a file named project_name.xml and put the following in it:

<Context path="/Serv1" docBase="webapps/project_name" 
         reloadable="true" debug="0" privileged="true">
</Context>

Now put the xml file in the webapps directory.

If you are deploying a WAR then replace the docBase as "webapps/project_name.war"

Adrian Regan
It is in the default namspace
artaxerxe
This is not enough - does the servlet have a package? If it does, the full path to the package should precede the servlet name, just as Adrian has said.
Yuval F
This does not matter, if you do not put your servlet into a package, tomcat will look for it on what it considers to be it's current directory. Put it in a package and reference the package from the servlet-class tag.
Adrian Regan
no matter what i do, it doesn't work. I packaged it, recompiled... Unsuccessfully
artaxerxe
Are you trying to access resources in the constructor or init of your servlet. If so, are they referenced by the package they reside in?
Adrian Regan
the mistake was at <servlet-url> tag in <servlet-mapping>. It must to be <url-pattern>. Uuuuf... I beg your pardon:)
artaxerxe
Whoa, should have spotted that myself.
Adrian Regan
A: 

It looks like you need to put your servlet in a package, e.g. com.me.Ch1Servlet. Then change the servlet-class declaration to <servlet-class>com.me.Ch1Servlet</servlet-class>

lrussell
i have also done this after Adrian's post, but also doesn't work
artaxerxe
A: 

How about http://localhost:8080/Serv1 without the webapp name in the URL?

ktaylorjohn
Not work anyway
artaxerxe
+1  A: 

You need to throw what you have away, start again and go through this very carefully:

http://tomcat.apache.org/tomcat-6.0-doc/appdev/index.html

What have you learned so far?

  1. Your servlet .class needs to be in a package. You should see WEB-INF/classes/com.foo.Bar.class if your class is Bar.jar with a package com.foo; at the top
  2. Package your app into a WAR named MyApp and put it in /webapps to deploy it.
  3. The URL needs to be http://localhost:8080/MyApp/Bar if you map com.foo.Bar to /Bar

Forcing people to make suggestions, and repeating that "it doesn't work", isn't going to get you where you need to be.

duffymo