First Servlet

Reply

Join Date: Apr 2008
Posts: 1
Reputation: irtiza is an unknown quantity at this point 
Solved Threads: 0
irtiza irtiza is offline Offline
Newbie Poster

First Servlet

 
0
  #1
Apr 14th, 2008
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...
  1. <?xml version="1.0" encoding="ISO-8859-1"?>
  2. <web-app xmlns="http://java.sun.com/xml/ns/javaee"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
  5. version="2.5">
  6. <servlet>
  7. <servlet-name>HelloWorldServlet</servlet-name>
  8. <servlet-class>servlets.HelloWorldServlet</servlet-class>
  9. </servlet>
  10.  
  11. <servlet>
  12. <servlet-name>LoginServlet</servlet-name>
  13. <servlet-class>servlets.LoginServlet</servlet-class>
  14. </servlet>
  15.  
  16. <servlet-mapping>
  17. <servlet-name>HelloWorldServlet</servlet-name>
  18. <url-pattern>/HelloWorldServlet</url-pattern>
  19. </servlet-mapping>
  20.  
  21. <servlet-mapping>
  22. <servlet-name>LoginServlet</servlet-name>
  23. <url-pattern>/LoginServlet</url-pattern>
  24. </servlet-mapping>
  25.  
  26. </web-app>

The HelloWorldServlet.java is
  1. package servlets;
  2.  
  3. import java.io.IOException;
  4. import java.io.PrintWriter;
  5. import javax.servlet.ServletException;
  6. import javax.servlet.http.HttpServlet;
  7. import javax.servlet.http.HttpServletRequest;
  8. import javax.servlet.http.HttpServletResponse;
  9.  
  10.  
  11. public class HelloWorldServlet extends HttpServlet{
  12. public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
  13. PrintWriter pw = response.getWriter();
  14. pw.println("<html>");
  15. pw.println("<head>");
  16. pw.println("</head>");
  17. pw.println("<body>");
  18. pw.println("<h3>Hello World as a Servlet</h3>");
  19. pw.println("</body>");
  20. pw.println("</html>");
  21. }
  22. }

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

http://localhost:8080/ServletExamples/HelloWorldServlet

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

Regards

ISI
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 307
Reputation: Thirusha is an unknown quantity at this point 
Solved Threads: 48
Thirusha's Avatar
Thirusha Thirusha is offline Offline
Posting Whiz

Re: First Servlet

 
0
  #2
Apr 14th, 2008
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/
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 1
Reputation: sinan.yumak is an unknown quantity at this point 
Solved Threads: 0
sinan.yumak sinan.yumak is offline Offline
Newbie Poster

Re: First Servlet

 
0
  #3
Apr 20th, 2008
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".
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC