1

I am trying to deploy a servlet on Tomcat from Eclipse using WTP plugin. Eclipse is working fine and Tomcat is also up. As when I open http://localhost:8080 I get the home page of Tomcat. I am following this exact tutorial http://www.vogella.com/articles/EclipseWTP/article.html but when I try to deploy it on tomcat by right clicking on servlet class and run as run on server I get following error. The requested resource (/test/FileCounter) is not available. I searched but could not find anything which could help me. I am using Eclipse Java EE IDE and Tomcat 6. Following is my web.xml file

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>test</display-name>
  <servlet>
    <description></description>
    <display-name>FileCounter</display-name>
    <servlet-name>FileCounter</servlet-name>
    <servlet-class>com.servlets.FileCounter</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>FileCounter</servlet-name>
    <url-pattern>/FileCounter</url-pattern>
  </servlet-mapping>
</web-app>
4

2 に答える 2

5

I faced this same problem and just solved it !

In the Project Explorer , expand the Deployment descriptor ( just above the Java resource ) . Then expand "servlet" in that deployment descriptor , their should be your created Servlet. Right click on it and Run as --> Run on server .

But one thing isn't clear to me in Eclipse that web.xml is not defined properly but the servlet is running without it !

于 2012-12-10T20:30:00.943 に答える
0

I just had this same problem. It appears from some reason when I created the servlet through the servlet wizard, eclipse did not create a web.xml file in the WebContent WEB-INF folder. I don't know why it didn't create it.

I added the web.xml file into the WebContent/WEB-INF folder and when I did that, I had a servlet under deployment descriptor that I could right click on and run as -> run on server

Here is the web.xml file you need:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>test</display-name>
  <servlet>
    <description></description>
    <display-name>FileCounter</display-name>
    <servlet-name>FileCounter</servlet-name>
    <servlet-class>your.servlet.path.filecounter.servlets.FileCounter</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>FileCounter</servlet-name>
    <url-pattern>/FileCounter</url-pattern>
  </servlet-mapping>
</web-app>

Of course you will want to update your servlet class to the package name you created

于 2013-06-13T18:24:56.190 に答える