Unable to compile Servlet

Unable to compile Servlet

First I installed the tomcat server in C:\apache-tomcat-6.0.14 directory.

Then I created a system variable CATALINA_HOME with the value C:\apache-tomcat-6.0.14.

Then I created another system variable JAVA_HOME with the value C:\Program Files\Java\jdk1.6.0.14

Then I created another environment variable CLASSPATH with the value C:\apache-tomcat-6.0.14\lib\servlet-api.jar

Then I created my servlet file Servlet_LifeCycle.java under the folder C:\apache-tomcat-6.0.14\webapps\demo-examples. The demo-examples folder was created by me.

To compile my servlet program I did the following:

C:\apache-tomcat-6.0.14\webapps\demo-examples>javac Servlet_LifeCycle.java

But the compilation failed totally.

View Answers

January 25, 2011 at 4:44 PM

Hi Friend,

Follow these steps:

1)create a servlet.

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class HelloWorld extends HttpServlet{ 
  public void doGet(HttpServletRequest request, HttpServletResponse response)
                                   throws ServletException,IOException{
    response.setContentType("text/html");
    PrintWriter pw = response.getWriter();
    pw.println("<html>");
    pw.println("<head><title>Hello World</title></title>");
    pw.println("<body>");
    pw.println("<h1>Hello World</h1>");
    pw.println("</body></html>");
  }
}

2)Go to the webapps folder of your apache tomcat and create a web application folder but it should having an appropriate name like examples.

3)Create web.xml and classes folder inside the WEB_INF folder of web application folder assuming examples.

4)Copy the servlet to the classes folder.

5)Edit the web.xml to include servlet?s name and url pattern.

 <servlet>
  <servlet-name>Hello</servlet-name>
  <servlet-class>HelloWorld</servlet-class>
 </servlet>
 <servlet-mapping>
 <servlet-name>Hello</servlet-name>
 <url-pattern>/HelloWorld</url-pattern>
 </servlet-mapping>

6)Compile your servlet.

7)Run Tomcat server by clicking the startup.bat file. This is located inside the bin folder of apache tomcat.

8)Open the browser and type the following url:

http://localhost:8080/webapplicationfoldername/servletname

For more information, visit the following link:

http://www.roseindia.net/servlets/introductiontoconfigrationservlet.shtml

Thanks









Related Tutorials/Questions & Answers:
Unable to compile Servlet
Unable to compile Servlet  First I installed the tomcat server in C... was created by me. To compile my servlet program I did the following: C:\apache...\servlet-api.jar Then I created my servlet file Servlet_LifeCycle.java under
unable to compile class file - JSP-Servlet
unable to compile class file  I wrote database connection in jsp file. I have form in html. In html form i put drop down list box in that form... in that dropdown list box.   Hi, dynamic bombobox in servlet
Advertisements
Unable to compile class for JSP - WebSevices
Unable to compile class for JSP  org.apache.jasper.JasperException: Unable to compile class for JSP When I am trying to access a java file kept under src folder under a package from a jsp page placed under web directory, I am
unable to run servlet
-mapping> 6)Compile your servlet. 7)Run Tomcat server by clicking...-pattern>/HelloWorld</url-pattern> </servlet-mapping> 6)Compile your...-mapping> 6)Compile your servlet. 7)Run Tomcat server by clicking the startup.bat
servlet not compile - Java Beginners
servlet not compile  Hi friend, I am Using JDK 5.0 with that javax.servlet is not available so i download this package and put it in the src folder,but my program displayed "package not found" at the time of compilation
unable to connect to server - JSP-Servlet
unable to connect to server  thank you for the program code for inserting and reteriving the image but i am unable to deploy these two programs in weblogic/apache servers can any one help me how to do this ?   Hi Friend
how to compile and run servlet program
how to compile and run servlet program   hello sir/mam i hve installed tomcat5.5 version and also have jdk1.6.0_14 installed but not able to run it or compile i m doing it first tyme pls help me in sorting out this problem. i hve
unable to display table data on JSP page that is coming from mysql and servlet.
unable to display table data on JSP page that is coming from mysql and servlet.  I am unable to show table data on JSP page using servlet and mysql. only two rows data i showing but in my database I have five fields
unable to display table data on JSP page that is coming from mysql and servlet.
unable to display table data on JSP page that is coming from mysql and servlet.  I am unable to show table data on JSP page using servlet and mysql. only two rows data i showing but in my database I have five fields
unable to display table data on JSP page that is coming from mysql and servlet.
unable to display table data on JSP page that is coming from mysql and servlet.  I am unable to show table data on JSP page using servlet and mysql. only two rows data i showing but in my database I have five fields
Unable to run the jsp page - JSP-Servlet
Unable to run the jsp page  Expert:Naga Hi, I need solution this program. In cart.jsp I printed the total amount of the products then the next page is shipping and billing details and the next page is payment details. What
compile
compile  how to compile .class files using eclipse
compile
compile  how to compile a java program using jre7
unable to retrive the data from mysql using servlet using jdbc driver
unable to retrive the data from mysql using servlet using jdbc driver  Hi, i have a servlet program..to verify the login and redirect to correct...(request,response); } } .i am unable to redirect..here is the code..pls
Unable to run jsp files on internet explorer - JSP-Servlet
Unable to run jsp files on internet explorer  Hi, I am Akhilesh Shrivastav. I am new to jsp and a new member of this site. My problem is i wrote a small jsp program stored in the Web-Apps folder of Apache Tomcat. But i
javax. servlet.Servlet Exception: Initialization failed, Unable to get DB connection - JSP-Servlet
javax. servlet.Servlet Exception: Initialization failed, Unable to get DB... & sqlstatement from servlet init parameter String dbuser=getInitParameter("dbuser... ServletException("Initialization failed, Unable to get DB connection
how to access radio buttons selected in a servlet??...iam unable to retrieve values...it is returning NULL
how to access radio buttons selected in a servlet??...iam unable to retrieve values...it is returning NULL  <html> <head> <title>online exam</title> </head> <body> <div
how to access radio buttons selected in a servlet??...iam unable to retrieve values...it is returning NULL
how to access radio buttons selected in a servlet??...iam unable to retrieve values...it is returning NULL  <html> <head> <title>online exam</title> </head> <body> <div
unable to display image using html tag in servlet.(image src is in a variable.....). i am using netbeans IDE. plz..........do help
unable to display image using html tag in servlet.(image src is in a variable.....). i am using netbeans IDE. plz..........do help  import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException
unable to execute the examples
unable to execute the examples  unable to execute the examples given for struts,ejb,or spring tutorials.Please help I am a beginner
compile error
compile error  Hello All for example public class A { static void main(String args[]) { System.out.println("Hello World... program with Test.java and try to compile with javac test.java an error like
unable to open the service tomcat5
unable to open the service tomcat5  While trying to run tomcat server getting "unable to open the service tomcat5" error after installed tomcat
Unable to understand Struts - Struts
Unable to understand Struts  I am studying in GNIIT from NIIT. Here... { /** * Processes requests for both HTTP GET and POST methods. * @param request servlet request * @param response servlet response * @throws ServletException
unable to connect database in java
unable to connect database in java  Hello Everyone! i was trying to connect database with my application by using java but i am unable to connect... created. 6) Restart your compiler and compile your java code. For Inserting Data
JAVA Compile Question ?
JAVA Compile Question ?  I'm unable to compile this file and not sure why? Can someone please help? import java.nio.file.*; import java.nio.file.attribute.*; import java.nio.file.attribute.Attributes; import
Unable to Create DSN for
Unable to Create DSN for   I have installed Oracle 11g R2 and JDK7 in my Computer (Windows 7 Ultimate x64) . And, I want to work with Type 1 JDBC Driver. I'm unable to crate DNS for "Microsoft ODBC for Oracle", It gives eror
Unable to locate package openjdk-11-jdk
Unable to locate package openjdk-11-jdk  Hi, I want to install open jdk 11 on ubuntu with the following command: sudo apt install openjdk-11-jdk... information... Done E: Unable to locate package openjdk-11-jdk How to resolve
unable to connect database in java
unable to connect database in java  Hello Everyone! i was trying to connect database with my application by using java but i am unable to connect... i was using this code.... try { Driver d=(Driver)Class.forName
Unable to execute JSP page
Unable to execute JSP page  I have written one jsp file. It contains html tags and jsp directives. I have saved the file with the extension .jsp. The tomcat server is already running onto my machine. I have saved the jsp file
Unable to use JMXMP with Knopflerfish?
Unable to use JMXMP with Knopflerfish?  I have a bundle which runs properly with Eclipse, then I generate the jar file and try to use it with Knopflerfish, then I get the following exception java.net.MalformedURLException
Unable to store the image into database
Unable to store the image into database  Hello, I have created below program and program is throwing FileNotFound exception when I pressed the submit button. The problem is coming due to JSP page is not able to find complete path
unable to insert data into database
unable to insert data into database    hello.i have a problem in inserting data into database.i have used two prepared statement.one for retrieving the eid based on ename and the other is inserting data into database based
unable to insert data into database
unable to insert data into database    hello.i have a problem in inserting data into database.i have used two prepared statement.one for retrieving the eid based on ename and the other is inserting data into database based
unable to insert data into database
unable to insert data into database    hello.i have a problem in inserting data into database.i have used two prepared statement.one for retrieving the eid based on ename and the other is inserting data into database based
unable to insert data into database
unable to insert data into database    hello.i have a problem in inserting data into database.i have used two prepared statement.one for retrieving the eid based on ename and the other is inserting data into database based
unable to import class com.opensymphony.xwork2.ActionContext not found
unable to import class com.opensymphony.xwork2.ActionContext not found  Imported class com.opensymphony.xwork2.ActionContext not found gettin the above error
Servlet
-pattern> </servlet-mapping> </web-app> 6)Compile your servlet. 7...Servlet  I want to know the steps to write a simple servlet program... .   Hello Friend, Follow these steps: Put servlet-api.jar inside
Servlet
Servlet  What is Servlet
servlet hibernate - Hibernate
servlet hibernate  i store the data in database using servlet and hibernate.but unable to retrive plz help me
ModuleNotFoundError: No module named 'compile'
ModuleNotFoundError: No module named 'compile'  Hi, My Python... 'compile' How to remove the ModuleNotFoundError: No module named 'compile... to install padas library. You can install compile python with following command
ModuleNotFoundError: No module named 'compile'
ModuleNotFoundError: No module named 'compile'  Hi, My Python... 'compile' How to remove the ModuleNotFoundError: No module named 'compile... to install padas library. You can install compile python with following command
unable to see the output of applet. - Applet
unable to see the output of applet.  Sir, I was going through the following tutorial http://www.roseindia.net/java/example/java/applet.... u just copy that java source code and compile that using javac then you
How to compile and run the JSP
How to compile and run the JSP  Hi Kindly tell me how to run and compile JSP small Program using Tomcat as webserver. I created small program HELLO JSP in HTML and compile the program but it is saying Class o r interface
Servlet
Servlet  how to navigate one servlet page to another servlet page
Compile error - WebSevices
Compile error  Hello, How to read .pdf file using Javascript/php. Any one send the code
compile and run java program
compile and run java program  Hello, everyone!!! I just want to ask if you anyone here knows how to compile java file in linux specifically UBUNTU..._TO_REPLACE_1 how do I compile and run this file using the terminal of ubuntu
how to compile programs??????????
how to compile programs??????????  "javac" is not recognised as a file name. why??????????   Have you set your path name and class name correctly? Anyways have a look at the following link: Install Java
Compile time error
Compile time error  Hi, When i compile my simple program in cmd am getting a error like "Javac is not a recognized as an internal or external command, operable program or batch file" How to resolve this problem ????  
compile a java class
compile a java class  Hi, Am having a class ExampleOne.java in the location C:\learn\ExampleOne.java I want the class file to be present in C:\. I don't want to add any package details in the code. Is is possible to get
compile a java class
compile a java class  Hi, Am having a class ExampleOne.java in the location C:\learn\ExampleOne.java I want the class file to be present in C:\. I don't want to add any package details in the code. Is is possible to get

Ads