| Author |
Servlet basic program
|
aresh babu
Ranch Hand
Joined: Aug 31, 2008
Posts: 65
|
|
Hello,
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
class Ch1Servlet extends HttpServlet
{
public void doGet(HttpServletRequest req,HttpServletResponse res)
{
PrintWriter out=response.getWriter();
java.util.Date today=new java.util.Date();
out.println("<html>"+"<body>"+"h1 align=center>HF\'s Chappter1 Servlet</h1>"
+" "+today+"</body>"+"</html>");
}
}
While compiling this program i am getting these errors
Ch1Servlet.java:1: package javax.servlet does not exist
import javax.servlet.*;
^
Ch1Servlet.java:2: package javax.servlet.http does not exist
import javax.servlet.http.*;
^
Ch1Servlet.java:4: cannot find symbol
symbol: class HttpServlet
class Ch1Servlet extends HttpServlet
^
Ch1Servlet.java:6: cannot find symbol
symbol : class HttpServletRequest
location: class Ch1Servlet
public void doGet(HttpServletRequest req,HttpServletResponse res)
^
Ch1Servlet.java:6: cannot find symbol
symbol : class HttpServletResponse
location: class Ch1Servlet
public void doGet(HttpServletRequest req,HttpServletResponse res)
^
Ch1Servlet.java:8: cannot find symbol
symbol : variable response
location: class Ch1Servlet
PrintWriter out=response.getWriter();
^
6 errors
I already added the servlet-api.jar to the class path.
How can i overcome these errors? Please help me to rectify these errors.
Thank You
|
 |
Sreedhar Siliveri
Greenhorn
Joined: Nov 05, 2008
Posts: 2
|
|
Aresh
try making your servlet class public and then compile it ... this is going to be run with the help of web container.
Sreedhar
|
 |
Balu Sadhasivam
Ranch Hand
Joined: Jan 01, 2009
Posts: 874
|
|
servlet-api jar is not recognised. and probably your classpath is not correct . What servlet container are you using ? how do you setup classpath ? For jars , complete path with jar to be used in classpath.
In windows : type in cmd like CLASSPATH
In Unix : type env to find out the vlaue set for CLASSPATH.
You can also compile servlet using javac -classpath test.java
|
 |
aresh babu
Ranch Hand
Joined: Aug 31, 2008
Posts: 65
|
|
Hello Balu sadashivam,
i am using Tomcat6.0 as a servlet container and i wrote the classpath is as follows
C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\servlet-api.jar;
But i am unable to compile the program.
Whats wrong in this classpath?
What should i do to compile this program
|
 |
Balu Sadhasivam
Ranch Hand
Joined: Jan 01, 2009
Posts: 874
|
|
Can you try pinting out CLASSPATH in cmd and check ?
How did you setup CLASSPATH and compile ? Are you usng IDE ? or ant ?
set CLASSPATH=.;C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\servlet-api.jar;
|
 |
aresh babu
Ranch Hand
Joined: Aug 31, 2008
Posts: 65
|
|
Hello Balu Sadashivam,
I compiled the program by changing the classpath as you have given.
I am preparing for SCWCD for that reason i am not using any IDE.
My i know about Ant and how it is helpful?
Thank You for your guidance,
Aresh Babu
|
 |
Balu Sadhasivam
Ranch Hand
Joined: Jan 01, 2009
Posts: 874
|
|
Ant is a build tool which is handy when compiling projects.. To get heads up check out the inhouse material Ant and Ant manual
cheers
Balu
|
 |
 |
|
|
subject: Servlet basic program
|
|
|