• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

not able to run simple servlet

 
Ranch Hand
Posts: 156
Hibernate Eclipse IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 .
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic