I'm really new to Servlet and JSP programming.I downloaded Tomcat and have the server running. When I try and complie this code I get errors.
import java.io.*;
import javax.servlet.http.*;
public class MyHelloWorld extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException
{
response.setContentType("text/html");
PrintWriter out=response.getWriter();
out.println("<html>");
out.println("<body>");
out.println("<head>");
out.println("<title>Hello World,!</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Hello World</h1>");
out.println("</body>");
out.println("</html>");
}
}
these are the errors I get:MyHelloWorld.java:2: package javax.servlet.http does not exist
import javax.servlet.http.*;
^
MyHelloWorld.java:3: cannot find symbol
symbol: class HttpServlet
public class MyHelloWorld extends HttpServlet
^
MyHelloWorld.java:5: cannot find symbol
symbol : class HttpServletRequest
location: class MyHelloWorld
public void doGet(HttpServletRequest request,HttpServletResponse respons
e) throws IOException
^
MyHelloWorld.java:5: cannot find symbol
symbol : class HttpServletResponse
location: class MyHelloWorld
public void doGet(HttpServletRequest request,HttpServletResponse respons
e) throws IOException
^
4 errors
Please let me know what I am doing wrong! I have a huge assignmnet based on Servlets due this tuesday and I can't even get the sample code to run!
-
Servlet problem (5 messages)
- Posted by: neha sharma
- Posted on: July 22 2005 21:59 EDT
Threaded Messages (5)
- Check your classpath by Branko Juric on July 23 2005 00:15 EDT
- Check your classpath by neha sharma on July 23 2005 00:51 EDT
- hai neha sharma, you have to set classpath by chaitanya borusu on July 23 2005 17:57 EDT
- You should check your classpath by Nan Yuan on July 23 2005 21:13 EDT
- You should check your classpath by neha sharma on July 24 2005 00:37 EDT
-
Check your classpath[ Go to top ]
- Posted by: Branko Juric
- Posted on: July 23 2005 00:15 EDT
- in response to neha sharma
Make sure the servlet JAR is in your class path when you compile. Good luck with your assignment. -
Check your classpath[ Go to top ]
- Posted by: neha sharma
- Posted on: July 23 2005 00:51 EDT
- in response to Branko Juric
I dont know what you mean by that. Could you tell me an example. My prof told me to compile it like a normal java program. -
hai neha sharma, you have to set classpath[ Go to top ]
- Posted by: chaitanya borusu
- Posted on: July 23 2005 17:57 EDT
- in response to neha sharma
hai neha, installing tomcat is not enough , u must have servlet api to compile a servlet program. if u have complete j2ee software onto your system and even then u get this errors, then u have to set classpath.
And one more thing in your code u have to import javax.servlet.* class also and ur doget() method must throw servletexception also. -
You should check your classpath[ Go to top ]
- Posted by: Nan Yuan
- Posted on: July 23 2005 21:13 EDT
- in response to neha sharma
I don't know whether you use console to complie your java programme or not. If you use the console, first you should set the environment variable, for example, you should
c:\>set classpath=%classpath%;%CATALINA_HOME%/common/lib/servlet-api.jar;
CATALINA_HOME is the installed directory of your Tomcat. Such us c:\tomcat-5.0.28. -
You should check your classpath[ Go to top ]
- Posted by: neha sharma
- Posted on: July 24 2005 00:37 EDT
- in response to Nan Yuan
oh thanks!! It works!