Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa HTML Unable to compile Servlet
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Basumitra Mitra
Unable to compile Servlet
1 Answer(s)      3 years and 10 months ago
Posted in : HTML


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.


Advertisement
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
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 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
compile
compile  how to compile .class files using eclipse
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
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
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
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
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 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
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
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
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
Compile error - WebSevices
Compile error  Hello, How to read .pdf file using Javascript/php. Any one send the code
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
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... do I compile and run this file using the terminal of ubuntu... By the way, I am
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
compile time error
compile time error  my program compile successfully and make the class file also but when i tried to do next command to see the output,it showing error that "could not find or load main class fibbo" fibbo is my class name
compile time error
compile time error  my program compile successfully and make the class file also but when i tried to do next command to see the output,it showing error that "could not find or load main class fibbo" fibbo is my class name
compile time error
compile time error  my program compile successfully and make the class file also but when i tried to do next command to see the output,it showing error that "could not find or load main class fibbo" fibbo is my class name
 

 

 

DMCA.com