Tutorial: Creating Java Web Application
In this tutorial you will learn how to create a simple Hello World Java web application. The application will not use any IDE and will solely depend on what JDK provides.
So, let start with our first java hello world web application.
Pre-Requisites
1- Download JDK from here. Latest JDK version at the time of writing this tutorial is 6.
2- Download and install/unzip Apache Tomcat web server (zip or tar for Linux or installer) from here
Set up Java environment on your machine
Please refer to Install And Configure JDK On Windows
Set up Apache Tomcat environment on your machine
Please refer to Set Up Apache Tomcat On Windows
Now your JDK and Tomcat is setup. We will start developing our web application. This will be a very simple web application in which only one JSP will be created and it will print some text in browser.
Lets get started.
1- Create a folder Helloworld anywhere on your machine
2- Create a JSP file helloworld.jsp under this folder.
3- Put the following code in helloworld.jsp
<html> <head> <title>Hello world</title> </head> <body> <h1>Hello World!!!</h1> </body> </html>
4- Create folder Helloworld/WEB-INF
5- Create a file web.xml in WEB-INF and put the following code in this file
<web-app version="2.5" xsi:schemaLocation=" http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <welcome-file-list> <welcome-file>helloworld.jsp</welcome-file> </welcome-file-list> </web-app>
6- That’s it. We are done with the coding part. Now copy the entire Helloworld folder and put it in <tomcat-home>/webapps
7- Start tomcat server, <tomcat-home>/bin/startup.bat
8- Open your browser, and access the following URL http://localhost:8080/Helloworld
Enjoy!
Comments