Tutorial: Java/JSP Hello World Web Application in Eclipse

Pre-Requisites

  • Eclipse : I am using Eclipse 3.4 (Ganymede) for this application. You can download the latest version from here
  • Tomcat : download from here

 

Level: beginners

This application is for newbie how want to start java web development. In this application we will create a web application in Eclipse platform and the application will be deployed on Tomcat web server. This application will only show some output on the JSP page.

Lets start with our application

1- Open Eclipse

2- Go to New > Other

 

others

 

3- Select Dynamic Web Project

others

 

4- Provide a project name and press Finish

 

new project

 

5- Following project hierarchy will be created by Eclipse

 

New project hierarchy

 

6- create a package jsp under WebContent. Right click WebContent New > Folder

 

jsp package

 

7- Provide a name to the folder and press Finish

 

jsp packagea

 

8- Create a new jsp page. Right click jsp folder New > Other and select JSP and press Next

 

create jsp

 

 

9- Provide JSP a name and press Finish

 

provide jsp name

 

10-  Put following code in JSP

 
 
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body> 
<h1> Hello World !!! </h1>
 
</body>
</html>
 

11-  The other important file is web.xml.  Put the following code in web.xml


 
 
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
 http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
 
<?xml version="1.0" encoding="UTF-8"?>
    <display-name>Helloworld</display-name>
    <welcome-file-list>
        <welcome-file>/jsp/helloworld.jsp</welcome-file>
    </welcome-file-list>
</web-app>
 


12- Now we have to configure Tomcat Web Server.  Go to Window > Preferences > Server > Runtime Environment and press Add.

 

add server

 

13- On the next screen press Apache > Apache Tomcat v6.0, press Next

 

select tomcat 6


14-  On the next screen Browse to the Apache tomcat home directory and press Finish and then OK.

 

 browse tomcat

 

15- Now its time to run the project. Right click the project > Run As > Run on Server. Press Finish if any other options appear.

 

run as

 

16- Fire up your browser and provide the following URL http://localhost:8080/Helloworld/ and you will see something similar to the following output.

 

ouput

 

That’s it, we are done with our first JSP web application.

Downloads

Download the full project from here

Enjoy!



Related Links

Java Hello World Application With MyEclipse

Written by ali on December 20, 2009 under J2EE, Tutorial.

Comments

No Comments

Add a Comment

* means field is required.

Name *

Mail *

Website