How to run a jsp or servlet program?

I am a freshman of jsp and servlet,and i setup a j2se sdk on my computer before,and i can ran the java program that include main method correctly.But now i can't run jsp or servlet program.

For example:HelloWorld.java

code like the following:

import java.io.*;

import javax.servlet.*;

import javax.servlet.httpservlet.*;

publicclass HelloWorldextends HttpServlet

{

publicvoid doGet(HttpServletRequest request,HttpServletRequest response)

throws ServletException,IOException

{

PrintWriter out=response.getWriter();

out.println("Hello,world!");

}

}

The positon of the program:E:\new\HelloWorld.java

After ran the HelloWorld.java under command line,the result:

HelloWorld.java:2: package javax.servlet does not exist

import javax.servlet.*;

^

HelloWorld.java:3: package javax.servlet.httpservlet does not exist

import javax.servlet.httpservlet.*;

^

HelloWorld.java:4: cannot resolve symbol

symbol : class HttpServlet

location: class HelloWorld

public class HelloWorld extends HttpServlet

^

HelloWorld.java:6: cannot resolve symbol

symbol : class HttpServletRequest

location: class HelloWorld

public void doGet(HttpServletRequest request,HttpServletRequest response

)

^

HelloWorld.java:6: cannot resolve symbol

symbol : class HttpServletRequest

location: class HelloWorld

public void doGet(HttpServletRequest request,HttpServletRequest response

)

^

HelloWorld.java:7: cannot resolve symbol

symbol : class ServletException

location: class HelloWorld

throws ServletException,IOException

^

6 errors

I don't know why,what 's wrong with my settings or something else?

Please help me!!!

Thanks!

Yours

spark

[2412 byte] By [spark077a] at [2007-10-3 9:46:51]
# 1

to run a simple java program, you run it on a JVM (the jdk you installed on your box)

to run a servlet you have to install an J2EE server, as it is a web-based technology

remember J2EE != J2SE (in fact J2EE include J2SE, and is way more complex)

i cannot force you to read a tutorial but i can refuse to help if you don't (sincerly, it would be good idea :)

alban.maillerea at 2007-7-15 5:03:43 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
you have to set the CLASSPATH to servlet-api.jar(tomcat) or weblogic.jar in weblogic or copy either of these files in you'r current directory and then set the classpath to the fileSET CLASSPATH=%CLASSPATH%;servlet-api.jar in windowsyou have to use export in case of linux
qatadaa at 2007-7-15 5:03:43 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
1. install ur apeche tomcat2. set ur " environment variable".... create a new "CLASSPATH"3. and type in ur apeche tomcat directory "C:\.......\common\lib\servlet.api"4. apply and and OK it5. re-compile ur xxx.java
problemAnga at 2007-7-15 5:03:43 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

for executing servelet prog first of all u must compile the servelet class.

create a folder in web server (tomcat,weblogic etc,)with the samename

WEB_INF under that directory create two folders with the same name

ie lib and classes.

copy the servelet class in the classes directory.

and make the changes in web .xml file

then run it

NANDAa at 2007-7-15 5:03:43 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

hi,

have you installed the weblogic or tomcat servers.If u installed the weblogic server run the command "setenv" available in bea/user_projects/domains/ folder or else u do one thing set the classpath pointing to servlet-api.jar file before compiling the servlet program.

For jsp you need not run the program when send the request to jsp file in browser the web container will automatically generate the corresponding servlet code and it will automatically generates the .class file if it successfully compiles the servlet code.You need not bother about that,ok.

siri2005a at 2007-7-15 5:03:43 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6
At times , i ve seen a very peculiar problem of windows not accepting the CLASSPATH , i mean you keep on setting the path but it shows you the same error, in that case you can try copying servlet-api.jar (for tomcat) in the directory where you kept your source file and try to compile.
Karan.Dhillona at 2007-7-15 5:03:43 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...