Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

not able to run simple servlet

 
santhoshkumar samala
Ranch Hand
Posts: 156
Eclipse IDE Hibernate Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I have j2sdk1.4.1 in my windows 2000 machine
I am able to run the java programs but not able to run servlets

my program is
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class Test extends HttpServlet
{
/*public void init(ServletConfig sc)throws ServletException
{
super.init(sc);
}*/
public void service(HttpServletRequest req, HttpServletResponse res) throws ServletException,IOException
{
res.setContentType("text/html");
PrintWriter pout=res.getWriter();
System.out.println("this is test servlet");
pout.println("<html><head></head>");
pout.println("<body bgcolor=cyan>");
pout.println("<h1> This is h1 tag </h1>");
pout.println("</body>");
pout.println("</html>");
}
}
Test.java:3: package javax.servlet does not exist
import javax.servlet.*;
^
Test.java:4: package javax.servlet.http does not exist
import javax.servlet.http.*;
^
Test.java:7: cannot resolve symbol
symbol : class HttpServlet
location: class vasu.Test
public class Test extends HttpServlet
^
Test.java:14: cannot resolve symbol
symbol : class HttpServletRequest
location: class vasu.Test
public void service(HttpServletRequest req, HttpServletResponse res) thr
ows ServletException,IOException
^
Test.java:14: cannot resolve symbol
symbol : class HttpServletResponse
location: class vasu.Test
public void service(HttpServletRequest req, HttpServletResponse res) thr
ows ServletException,IOException
^
Test.java:14: cannot resolve symbol
symbol : class ServletException
location: class vasu.Test
public void service(HttpServletRequest req, HttpServletResponse res) thr
ows ServletException,IOException

any body please help me
 
Nathaniel Stoddard
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to include the j2ee.jar file located in your lib directory of the installed j2ee distribution as part of your classpath when you compile your servlet. After that, assuming you correctly package your web application, you'll be just fine.
 
brams mun
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
along with the jar file, also just check, whether u have specified the servlet name and mapping correctly in web.xml......
nothing wrong with your code
 
Anuradha Krishna
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
The problem is only with the classpath variable. You need to compile with the path to the servlet jar file.
Refer to http://www.sitepoint.com/article/java-servlets-1/3
HTH.
Regards,
Anu
 
Sanjay Katiyar
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
just add servlet.jar in ur classpath .
Follow this:
My Computer -> Properties ->Advanced ->Environment Variables
then add a variable named CLASSPATH(if this is not already exist), give full path of the servlet.jar (C:\Tomcat..\common\lib\servlet.jar)
sanjay.
 
sevi satalkar
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
make sure that you have proper pacakage of servlet it will be available with Tomcat ,if you are using it.
the problem is only with your classpath set servlet.jar in it .
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic