"Error: 500 Internal Servlet Error" question

Hi !

I   am trying to run my first Java servlet (as a matter of fact it's the first example from
"Professional Java Server Programming" book).

1. I compile my HelloWorld.java
2. I place it at jsdk2.1\webpages\WEB-INF\servlets path.
3. I start startserver.bat
4. I enter the following URL in browser : http://localhost:8080/servlet/HelloWorld

Here is the error that I get :

Error: 500
Internal Servlet Error:
java.lang.ClassCastException: HelloWorld
      at com.sun.web.core.ServletWrapper.loadServlet(ServletWrapper.java:90)
      at com.sun.web.core.ServletWrapper.handleRequest(ServletWrapper.java:109)
      at com.sun.web.core.InvokerServlet.service(InvokerServlet.java:169)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:840)
      at com.sun.web.core.ServletWrapper.handleRequest(ServletWrapper.java:140)
      at com.sun.web.core.Context.handleRequest(Context.java:375)
      at com.sun.web.server.ConnectionHandler.run(Compiled Code)

What is wrong ?
I am using Windows NT 4 SP5, JDK 1.2, JSDK 2.1

Thanks a lot !

Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

Ravindra76Connect With a Mentor Commented:
Hi john123,

1.class path will be like this


In JSDK2.0, servletrunner will try to load from

c:\jsdkhome\examples directory.

To run your servlets in yourdirecotyr

servletrunner -d c:\yourdir

Best of luck

2.HelloWorld.code = HelloWorld

Your your servlet alias is Hello

Hello.code = HelloWorld
and request is


Best of luck

i guess its a servlet registration problem.

how abt,

1. Compile HelloWorld.java

import java.io.*;

import javax.servlet.*;
import javax.servlet.http.*;

 * This is a simple example of an HTTP Servlet.  It responds to the GET
 * and HEAD methods of the HTTP protocol.
public class HelloWorld extends HttpServlet
     * Handle the GET and HEAD methods by building a simple web page.
     * HEAD is just like GET, except that the server returns only the
     * headers (including content length) not the body we write.
    public void doGet (
      HttpServletRequest      request,
      HttpServletResponse      response
    ) throws ServletException, IOException
      PrintWriter            out;
      String                  title = "Simple Servlet Output";

      // set content type and other response header fields first

      // then write the data of the response
      out = response.getWriter();

      out.println("<H1>" + title + "</H1>");
      out.println("<P>This is output from HelloWorld.");

2. Have it in a directory c:\myservlets
3. in ur classpath have set Classpath=c:\jsdk2.0\bin
4. start ur servletrunner
>servletrunner -p 8080 -d c:\myservlets

from ur browser use,

does this work?

Hi john1313,

1.First check the servlet is public class or not.

2.Check ths class name and file name.

3.IF still problem, it is registration problem

BEst of luck
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  If you are using servletrunner available in JSDK means you have to register you servlet first.Go the servlet.properties file and register your servlet there.
     After registration put servlet file in appropriate directory where the servletrunner will look for servlets class files.
      Dont forget to declare your class as public.
    I hope this will work out.
Best of luck
john1313Author Commented:
Thanks for all your answers, but I still have a problem...

1. I checked that the servlet class is public
2. I checked the name of the class

Sgoms :
I use JSDK 2.1, there is no bin directory there. Maybe be because of
this the browser is unable to find your servlet.

Concerning servlet.properties :
I have to enter the following enteris :

# <servletname>.code=<servletclass>
# <servletname>.initparams=<name=value>,<name=value>

What is the <servletname> ? My classname is HelloWorld.class. What
should be the <servletname> ?
I have the Sun's example which works. There are the following enteries there :

Ans yet another question :
Do I need to add some ClassPath of JSDK. According to my book, in JDK 1.2 I have to move servlet.jar to JDK/JRE/LIB/EXT. Do I need something else ?
Does the  ClassPath palys the role during the  compilation and running as well or only during the compilation ?



Once post your code.

I think classcastexception menas it is not extending servlet

john1313Author Commented:
Finally it works ! Thanks for all your answers !

Guess, what was the problem ?!

I begun to rename my servlet to HelloWorld ->Hello or HelloWorld ->HelloWorld1 and it worked....

I have some other HelloWorld.class in my ClassPath...:-):-):-)

All Courses

From novice to tech pro — start learning today.