Results 1 to 6 of 6
- 03-20-2011, 01:50 PM #1
Member
- Join Date
- Mar 2011
- Posts
- 9
- Rep Power
- 0
6 Errors in my first servlet prog..help pls
Hello Friends...
I am a newbie on your site as well as i am new to servlets programming..
So need your help to solve my problem..
I have created a small servlet application as my first servlet program. But when i try to compile it then it gives me the following error..
javac command is not able to compile the program..
javac is not able to compile the servlet code..what could be the problem ???Java Code:import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class Ex1Http extends HttpServlet { public void service(HttpServletRequest req,HttpServletResponse res) throws IOException,ServletException { PrintWriter out = res.getWriter(); res.setContentType("text/html"); out.println("Hi...."); } }
The error is as follows:
C:\>javac Ex1Http.java
Ex1Http.java:2: package javax.servlet does not exist
import javax.servlet.*;
^
Ex1Http.java:3: package javax.servlet.http does not exist
import javax.servlet.http.*;
^
Ex1Http.java:5: cannot find symbol
symbol: class HttpServlet
public class Ex1Http extends HttpServlet
^
Ex1Http.java:7: cannot find symbol
symbol : class HttpServletRequest
location: class Ex1Http
public void service(HttpServletRequest req,HttpServletResponse res)
^
Ex1Http.java:7: cannot find symbol
symbol : class HttpServletResponse
location: class Ex1Http
public void service(HttpServletRequest req,HttpServletResponse res)
^
Ex1Http.java:8: cannot find symbol
symbol : class ServletException
location: class Ex1Http
throws IOException,ServletException
^
6 errors
I have already set my classpath for jdk as well as tomcat..
Thanks in advance if you could help me out..
- 03-20-2011, 03:41 PM #2
Member
- Join Date
- Mar 2011
- Location
- chennai
- Posts
- 55
- Rep Power
- 0
servlet errors
It is so simple to resolve.
The thing which we have to do is just set the CLASSPATH . To set the CLASSPATH we need servlet-api.jar file,
How to set the classpath:
goto mycomputer icon->right click on it-> select properties-> choose tab advanced-> select environment variables-> in the user variables click new type CLASSPATH in first field and in second paste the total path of the jar file like d:/folder/servlet-api.jar;.; then click on ok.
second one is goto command promt and go to the working directory and use the below command
set CLASSPATH=path/servlet-api.jar;.;
but if you use this we have to set the classpath every time we open the cmd prompt. ok.
- 03-20-2011, 04:08 PM #3
Member
- Join Date
- Mar 2011
- Posts
- 9
- Rep Power
- 0
Thanks for the reply...
But i have already set the classpath as per the environment variables to:
classpath - C:\tomcat7\lib\servlet-api.jar
path - C:\Java\jdk1.6.0_24\bin
After that also the java compiler is not been able to find the servlet file ??
- 03-20-2011, 04:10 PM #4
Member
- Join Date
- Mar 2011
- Posts
- 9
- Rep Power
- 0
If i am wrong somewhere then do let me suggest the whole path to be set as per the environment variable. My Tomcat and JDK are in C: drive..folder
how to set..what to set ??Classpath - " "
Path - " "
Java_Home - " "
- 03-20-2011, 05:19 PM #5
Member
- Join Date
- Mar 2011
- Location
- chennai
- Posts
- 55
- Rep Power
- 0
how you ended the classpath for every path we have to put ;.; at end otherwise it wont work.
if you done exactly.
copy the servlet-api.jar to your cwd(current working directory) and set the class path like this:
copy serlvet-api.jar to D:/cwd
in prompt-
d:\cwd\set CLASSPATH=servlet-api.jar;.; (then press enter)
then compile the program
d:\cwd\javac MyServlet.java
check this it definitely works.:rolleyes::cool:
- 03-21-2011, 10:13 AM #6
Moderator
- Join Date
- Apr 2009
- Posts
- 10,479
- Rep Power
- 16
First off, don't set the environment variables on your system.
That is not the place to set Java classpaths.
Use -cp to set the classpath on the call to javac, or set it locally as mentioned above (set CLASSPATH=etc etc). I'd stick that in a script for compiling that project (or learn ant). If you have all your jars in a single lib folder under your project (which is generally a good idea) then "javac -cp "lib/*.jar";." is a nice easy command to use.
Similar Threads
-
Error in Hibernate prog
By Keerthi in forum EclipseReplies: 6Last Post: 10-27-2009, 07:20 PM -
Running my prog.
By arcticM in forum AWT / SwingReplies: 3Last Post: 08-24-2009, 03:42 AM -
What I need to do more in this prog??
By eliCanzee in forum AWT / SwingReplies: 2Last Post: 06-01-2009, 03:47 AM -
want menu driven prog. who to take user i/p in the middle of the prog.
By Shyam Singh in forum New To JavaReplies: 1Last Post: 07-13-2008, 03:16 PM -
need a prog on java 2d applet
By bachelorswalk in forum Java AppletsReplies: 0Last Post: 12-25-2007, 05:26 PM


LinkBack URL
About LinkBacks

Bookmarks