This simple tutorial describes how you can print "Hello World!" string in your browser by writing a simple JSP (Java server pages) program developed using eclipse IDE.
Technologies used in this article
1. Create Dynamic Web Project
Select from the menu File --> New --> Dynamic Web Project.
Enter "HelloWorldJSP" as the project name. Keep rest of the settings as it is as shown in the following screenshot.
Click "Next" button.
Click "Next" button.
Check 'Generate web.xml deployment descriptor' checkbox and click "Finish" button and Eclipse IDE will generate the web project automatically as shown below
2. Create Jsp page
Right click on 'WebContent' folder and select from context menu New --> Jsp File.
Write "helloWorld.jsp" in the 'File Name' field and Click "Finish" button.
Eclipse will generate a jsp page and open the same in the JSP editor as shown below.
File: helloWorld.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>
</body>
</html>
4. Write JSP Code
Edit the generated 'helloWorld.jsp' as per the following code.
File: helloWorld.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>Hello World - JSP tutorial</title>
</head>
<body>
<%= "Hello World!" %>
</body>
</html>
5. Run Your Code
Right click on 'helloWorld.jsp' and select from context menu 'Run As' --> 'Run on Server'.
Select the existing tomcat server. If not available then manually define a new web server.
Click "Finish" button. HelloWorldJSP web application will be deployed in the tomcat web server.
6. Browser Output
Eclipse will open a browser and your server side jsp code will print 'Hello World!' in the browser.
Download SrcCodes
All code samples shown in this post are available in the following link HelloWorldJSP.zip
Comments