views:

49

answers:

3

I've compiled the source into the class Files, then putted at the folder:

Tomcat 5.5\WEB-INF\ROOT\classes\Files.class

And added this to the web.xml file:

<servlet>
    <servlet-name>Files</servlet-name>
    <servlet-class>Files</servlet-class>
</servlet>

But when I tried to access the URL http://localhost:8080/Files, I got this error from Tomcat: Tomcat 5.5 404 Error


Update: after adding <servlet-mapping> I'm now getting the following error:

exception

javax.servlet.ServletException: Error allocating a servlet instance
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:837)
org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:640)
org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1287)
java.lang.Thread.run(Unknown Source)

root cause

java.lang.NoClassDefFoundError: IllegalName: /Files
java.lang.ClassLoader.preDefineClass(Unknown Source)
java.lang.ClassLoader.defineClassCond(Unknown Source)
java.lang.ClassLoader.defineClass(Unknown Source)
java.security.SecureClassLoader.defineClass(Unknown Source)
org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:1960)
org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:931)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1405)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1284)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:837)
org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:640)
org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1287)
java.lang.Thread.run(Unknown Source)
+3  A: 

You also need to define a

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

To match the url pattern to the servlet

fd
I'm still getting the same error. **:(**
Nathan Campos
You may need to restart Tomcat, or at least reload the application. Did you try that?
fd
Of course, I've already tried all, re-compile and restart the server.
Nathan Campos
Are you sure you only put "/Files" in the url-pattern, and no where else?
fd
@fd: Just to make sure, the file is like this: http://freetexthost.com/ys4x6i116n
Nathan Campos
This is incorrect: <servlet-class>/Files</servlet-class>You need: <servlet-class>Files</servlet-class>
fd
+3  A: 

You also need the servlet-mapping:

<servlet-mapping>
  <servlet-name>Files</servlet-name>
  <url-pattern>/Files</url-pattern>
</servlet-mapping>
KLee1
I'm still getting the same error. **:(**
Nathan Campos
+1  A: 
root cause
java.lang.NoClassDefFoundError: IllegalName: /Files

This means that the given class definition cannot be found because it has an illegal name /Files. This in turn means that you've changed the <servlet-class> to /Files. This is wrong. You're basically instructing the servletcontainer to declare and instantiate the servlet as follows:

/Files Files = new /Files();

This won't already compile. The complete mapping should look like:

<servlet>
    <servlet-name>instanceName</servlet-name>
    <servlet-class>com.example.ServletClass</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>instanceName</servlet-name>
    <url-pattern>/urlPattern</url-pattern>
</servlet-mapping>

Which is to be interpreted in raw Java code as follows:

com.example.ServletClass instanceName = new com.example.ServletClass();

The <servlet-class> should denote the full qualified classname, including any package. The <servlet-name> should denote the unique instance name. The <url-pattern> should denote the URL pattern for which the servletcontainer should invoke this servlet.

BalusC