• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

please help...new to servlets

 
san geeta
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
my java version is j2sdk1.4.1_03.I have saved the servlet in bin subdirectory..Tomcat is properly initialised because the index page opens...But when i try to compile the servlet i get the following errors...please tell me where the problem lies.....

C:\j2sdk1.4.1_03\bin>javac MyFirstServlet.java
MyFirstServlet.java:4: package javax does not exist
import javax.servlet;
^
MyFirstServlet.java:5: package javax.servlet.htt does not exist
import javax.servlet.htt.HttpServletRequest;
^
MyFirstServlet.java:6: package javax.servlet.http does not exist
import javax.servlet.http.HttpServletResponse;
^
MyFirstServlet.java:8: package javax.servlet does not exist
import javax.servlet.ServletExcetion;
^
MyFirstServlet.java:10: cannot resolve symbol
symbol : class HttpServlet
location: class MyFirstServlet
public class MyFirstServlet extends HttpServlet
^
MyFirstServlet.java:12: cannot resolve symbol
symbol : class HttpServletRequest
location: class MyFirstServlet
public void doGet(HttpServletRequest request, HttpServletResponse respon
se) throws ServletException, IOException
^
MyFirstServlet.java:12: cannot resolve symbol
symbol : class HttpServletResponse
location: class MyFirstServlet
public void doGet(HttpServletRequest request, HttpServletResponse respon
se) throws ServletException, IOException
^
MyFirstServlet.java:12: cannot resolve symbol
symbol : class ServletException
location: class MyFirstServlet
public void doGet(HttpServletRequest request, HttpServletResponse respon
se) throws ServletException, IOException
^
8 errors
the servlet program is::

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet;
import javax.servlet.htt.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletExcetion;
public class MyFirstServlet extends HttpServlet
{
public void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException,
IOException
{
response.setContentType("text/plain");
PrintWriter out = response.getWriter();
out.println("This is my first servlet");
}
}
 
Srinivasan Mani
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to have j2ee.jar in your classpath.
 
Srinivasan Mani
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In case of tomcat, add
tomcat_home\common\lib\servlet.jar to classpath and then compile.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic