Getting Started Java Servlet and Apache Tomcat manually


Here is simple example to create Hello World program using Servlet Without  IDE:

I assume you already have installed Tomcat on your machine, and i assume you already have servlet-api.jar on your environment setting, if not you can go here ,

  1. First Step, create project folder and all needed folders under project folder, here is mine :
    • /home/yusuf/apache-tomcat-7.0.40/webapps
    • /home/yusuf/apache-tomcat-7.0.40/webapps/myfirstproject
    • /home/yusuf/apache-tomcat-7.0.40/webapps/myfirstproject/WEB-INF
    • /home/yusuf/apache-tomcat-7.0.40/webapps/myfirstproject/WEB-INF/classes
    • *path is relative, and here is my real local folder path.
  2. Then create HelloWorld.java, source code open here-> file
  3. You can place your HelloWorld.java anywhere you want, but you need to place your HelloWorld.class under /home/yusuf/apache-tomcat-7.0.40/webapps/classes
  4. Compile The file : [ysf@YusufCucokBo classes]$ javac HelloWorld.java , it will produce java class named HelloWorld.class
  5. Move/put your HelloWorld.class to become /home/yusuf/apache-tomcat-7.0.40/webapps/classes/HelloWorld.class
  6. Now let create /home/yusuf/apache-tomcat-7.0.40/webapps/WEB-INF/web.xml , source is here
  7. Now you have HelloWorld.class under classes folder and, web.xml under WEB-INF
    • /home/yusuf/apache-tomcat-7.0.40/webapps/myfirstproject/WEB-INF/web.xml
    • /home/yusuf/apache-tomcat-7.0.40/webapps/myfirstproject/WEB-INF/classes/HelloWorld.class
  8. Open your browser then go to : http://localhost:8080/myfirstproject/hai

One thought on “Getting Started Java Servlet and Apache Tomcat manually

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s