how to run servelets in java ..I think there is no error in my following code...In java compiler its tellin that package does not exists.

import java.io.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class HelloServelet extends GenericServelet
{
  public void service(ServletRequest request,ServletResponse response)throws ServletException, IOException
{
  response.setContentType("text/html");
  PrintWriter pw=response.getWriter();
  pw.println("<b> Hello");
  pw.close();
 }
}

While compling its showing following errors:

C:\Program Files\Java\jdk1.5.0\bin>javac HelloServelet.java
HelloServelet.java:4: package javax.servlet does not exist
import javax.servlet.*;
^
HelloServelet.java:5: package javax.servlet.http does not exist
import javax.servlet.http.*;
^
HelloServelet.java:7: cannot find symbol
symbol: class GenericServelet
public class HelloServelet extends GenericServelet
                                   ^
HelloServelet.java:9: cannot find symbol
symbol  : class ServletRequest
location: class HelloServelet
  public void service(ServletRequest request,ServletResponse response)throws Ser
vletException, IOException
                      ^
HelloServelet.java:9: cannot find symbol
symbol  : class ServletResponse
location: class HelloServelet
  public void service(ServletRequest request,ServletResponse response)throws Ser
vletException, IOException
                                             ^
HelloServelet.java:9: cannot find symbol
symbol  : class ServletException
location: class HelloServelet
  public void service(ServletRequest request,ServletResponse response)throws Ser
vletException, IOException
                                                                             ^
6 errors

You will need to add the required jarfile for the servlet API to your classpath.

You will need to add the required jarfile for the servlet API to your classpath.

wil u pls explain detaily ...I didnt get u

Have you installed Tomcat? If yes, then the IDE which you must be using would have an option for setting the class path for you.

Ya i installed tomcat .Do i hav 2 create any xml file for tat servlet program..In book its said tat after compiling in java, its corresponding class file should be pasted in root directory of tomcat.. But its not compiling...???

Yes you have to create web.xml entry for that servlet program and also set the classpath to point to your servlet and jsp jar files.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.