Hey Guys.....I am new in web development and this was supposed to be my first Servlet but I am getting

java.lang.ClassNotFoundException: servlets.HelloWorldServlet

Now in my Apache tomcat folder C:\apache-tomcat-6.0.16\webapps\ServletExamples I have the WEB-INF folder.....which has the web.xml....

Web.xml is something like this...

<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"

The HelloWorldServlet.java is

package servlets;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class HelloWorldServlet extends HttpServlet{
	public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
		PrintWriter pw = response.getWriter();
		pw.println("<h3>Hello World as a Servlet</h3>");

and this is what I am writing on the url......


and I am assuming that the problem is coming in the <servlet-class> in the fully qualified name....

So I decided to make a classes folder in the WEB-INF folder and copy all my .class files and .java files in it.....

after this I am still getting the same error....

java.lang.ClassNotFoundException: servlets.HelloWorldServlet

and when I refresh it again it gives me a different error....which is

type Status report

message Servlet HelloWorldServlet is not available

description The requested resource (Servlet HelloWorldServlet is not available) is not available.

So how can anybody help me out in starting my carrier in the servlets...

Thanks in advance



I too am new, but ClassNotFoundException is generally caused by the class file not being in the correct location. HelloWorldServlet class file needs to be in /web-inf/classes/servlets/

hi,there. I have downloaded your code and compiled it. It works. But you have to change package name to "servlets". just click Source Packages and then right click to default package and create a new java package. This packages name needs to be "servlets".

This article has been dead for over six months. Start a new discussion instead.