How to run a servlet program?
Answers were Sorted based on User's Feedback
Answer / subrahmanyam
We have to Make a WEB-INF folder and under it classes
folder. In WEB-INF we have to write web.xml .
Our compled servelet class file should be stored in classes
folder.
Make a war file using jar & deploy in Web.
| Is This Answer Correct ? | 97 Yes | 27 No |
Answer / anji
The structure of the web app. is
demo[root]
- all jsps will go her
- WEB-INF
- web.xml
- tld files
- classes
- all java class files will go here
Compile all the files and create a war file
copy the war file into Tomcat_root\webapps folder
if you use weblogic or webspehere the deployment will be
different.
| Is This Answer Correct ? | 41 Yes | 28 No |
Answer / suresh
we have make dir name is,WEB-INF is the root directory
WEB-INF
--classes dir
--lib dir
--src dir
--web.xml
-html file
-dhtml file
-jsp file
lib dir contains
--jasper-runtime.jar
--servlet-api.jar
--jsp-api.jar
your source code put in the src dir
--put the WEB-INF dir in your tomcat server and run the servlet
| Is This Answer Correct ? | 27 Yes | 15 No |
Answer / kunal sagar
first we con compile the java code throught javac compiler.
then,its .class file will be created that .class file copy
and paste the in the directory
c:/program files/apache/tomcat/webapps/servlet/web-inf
/classes.
then back one step backward
change the servlet code with ur file name
and also sevlet mapping code with ur file name
save that file
then open explorar
and type the local host address
| Is This Answer Correct ? | 18 Yes | 6 No |
Answer / vivek
To run a servlet one should follow the steps illustrated below:
Download and Install the tomcat server: Install the tomcat server in a directory in which you want to install and set the classpath.for the variable JAVA_HOME in the environment variable. To get details about the installation process and setting the classpath click the link Tomcat installation.
Set the class for the jar file: Set the classpath of the servlet-api.jar file in the variable CLASSPATH inside the environment variable by using the following steps.
For Windows XP,
Go to Start->Control Panel->System->Advanced->Environment Variables->New button and Set the values as
Variable Name: CLASSPATH
Variable Value: C:\Program Files\Java\Tomcat 6.0\lib\servlet-api.jar
For Windows 2000 and NT
Go to Start->Settings->Control Panel->System->Environment Variables->New button and Set the values as
Variable Name: CLASSPATH
Variable Value: C:\Program Files\Java\Tomcat 6.0\lib\servlet-api.jar
Create a java source file and a web.xml file in a directory structure.
Compile the java source file, put the compiled file (.class file) in the classes folder of your application and deploy the directory of your application in the webapps folder inside the tomcat directory.
Start the tomcat server, open a browser window and type the URL http://localhost:8080/directory (folder name of your application) name/servler name and press enter.
If everything is correct your servlet will run.
| Is This Answer Correct ? | 8 Yes | 5 No |
Answer / anil reddy
WEB-INF
--classes dir(.class)
--lib dir
--src dir(.java)
--web.xml
-html file
-dhtml file
-jsp file
=>tomcat on and goto browser type your html name(http:
\\localhost:8081\.html)
| Is This Answer Correct ? | 10 Yes | 10 No |
Sampleapplication
-- any html or jsp pages
-- WEB-INF
--web.xml
--lib(which contains any jar files)
--classes
--(all Servlet .class files)
After compilation of Servlet .java files start the Tomcat
Server and in URL type like:
http://localhost:8080/Sampleapplication/.html(or).jsp <--(enter)
| Is This Answer Correct ? | 5 Yes | 6 No |
How can a servlet be used to generate plain text instead of html?
How servlet is created?
What is the servletconfig object?
What do you mean by annotations in servlet?
What is difference between Forward() and sendRedirect() methode?
what happens if we wont use destroy()?
What's the difference between authentication and authorization?
Once the destroy() method is called by the container, will the servlet be immediately destroyed? What happens to the tasks(threads) that the servlet might be executing at that time?
Define servlet mapping?
Why is Servlet so popular?
What exception should be thrown when servlet is not properly initialized?
What do you mean by mime type?