0

I'm really going crazy in these days, I'm trying to develop a servlet, but I really can't understand why this one doesn't work.

Here's the code:

import java.io.IOException;
import javax.servlet.ServletException;

import java.io.BufferedReader;
import java.io.PrintWriter;

import javax.servlet.ServletResponse;
import javax.servlet.ServletRequest;
import javax.servlet.GenericServlet;

public class WipdServlet extends GenericServlet 
{
    public void service(ServletRequest request, ServletResponse response)
    throws IOException {
        PrintWriter out = response.getWriter();

        out.println("<html>");
        out.println("<body>");
        out.println("<h1>ssup WIPD Servlet</h1>");
        out.println("Content Type: " + request.getContentType());
        out.println("Content Length: " + request.getContentLength());
        out.println("</body>");
        out.println("</html>"); 

    }
}

And web.xml:

<web-app>
    <servlet>
        <servlet-name>Wipd</servlet-name>
        <servlet-class>WipdServlet</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>Wipd</servlet-name>
            <url-pattern>/wipd</url-pattern>    
    </servlet-mapping>
</web-app>

the servlet is under:

/var/lib/tomcat6/webapps/wipd/

For this work I need to run the servlet under Tomcat6 installed on a Debian running on a VM, I'm currently working on my Gentoo with servlet-api, after run javac on Gentoo I put file .class on Debian. But if i surf to:

http://192.168.0.177:8080/wipd/wipd.

I get:

javax.servlet.ServletException: Wrapper cannot find servlet class WipdServlet or a class it depends on org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293) org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859) org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602) org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489) java.lang.Thread.run(Thread.java:636)

I try even to put the class in a package, and edit web.xml specifying the package, but nothing. I'm really can't understand.

Thanks in advance.

alkz
  • 337
  • 2
  • 7
  • 17
  • This error also occurs when you have disabled automatic building of your projects in eclipse. so, there is no class file for all the java files/servlets that you have created. Hence, the error. To fix - `Select your project > Eclipse > Project > Build Project`. Run your code again. – Erran Morad May 11 '14 at 05:09

3 Answers3

0

From the exception i can see that your class is not in a package. check this link which describes similar problem to yours.

Community
  • 1
  • 1
PermGenError
  • 45,977
  • 8
  • 87
  • 106
0

You need to have your servlet in some package. Make following changes -

package a.b.c; // added

public class WipdServlet extends GenericServlet {

    // .. other code
}

web.xml :-

<web-app>
    <servlet>
        <servlet-name>Wipd</servlet-name>
        <servlet-class>a.b.c.WipdServlet</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>Wipd</servlet-name>
        <url-pattern>/wipd</url-pattern>    
    </servlet-mapping>
</web-app>

After you deploy, you should find your class at following location -

/var/lib/tomcat6/webapps/wipd/WEB-INF/classes/a/b/c/WipdServlet.class

devang
  • 5,376
  • 7
  • 34
  • 49
0

I faced the same problem too. Actually one of my program which was working already after few changes showed me this error. I even did undo to revert the changes, still It happened to me. Finally I found a working solution for this for my scenario.

SIMPLE:

1.Just try to clean your project and run again. If it shows the same error and if you are sure there isn't any problem with your code then,

2.Enable the "Build Automatically" menu item under "Project" menu and try to clean your project. This time it worked for me.

Heard this is because when we make some changes and run, eclipse does some changes in its background too. So even if we revert the changes, eclipse might have not reverted the changes which it did in background. So performing these 2 steps will make sure it matches with the user change with its background change.

Hope it helps and solves your problem too.

Tapeshvar
  • 338
  • 1
  • 13