This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Servlets and the fly likes not able to run simple servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "not able to run simple servlet " Watch "not able to run simple servlet " New topic
Author

not able to run simple servlet

santhoshkumar samala
Ranch Hand

Joined: Nov 12, 2003
Posts: 156

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


santhosh<br />SCJP,SCWCD
Nathaniel Stoddard
Ranch Hand

Joined: May 29, 2003
Posts: 1258
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.


Nathaniel Stodard<br />SCJP, SCJD, SCWCD, SCBCD, SCDJWS, ICAD, ICSD, ICED
brams mun
Greenhorn

Joined: Nov 27, 2003
Posts: 25
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

Joined: Mar 14, 2004
Posts: 6
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

Joined: Mar 23, 2004
Posts: 1
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

Joined: Mar 03, 2004
Posts: 7
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.
 
subject: not able to run simple servlet