- Hi friends today we will see basic example of how to run jsp (java server pages) program using tomcat server in eclipse IDE.
- For this we need to create dynamic web project in eclipse
- Lets see how to run jsp program in tomcat server step by step.
- Print hello world using jsp program
Required software:
- Eclipse IDE: Download latest eclipse IDE
- Tomcat Sever: Download latest tomcat server
- After downloading eclipse and tomcat server. open eclipse and add server and select tomcat version and giver downloaded tomcat folder path.
Step 1: Open eclipse and create dynamic web project:
- Now we need to create dynamic web project for this in eclipse
- New => other=> web=> Dynamic web project
Step 2 : Create a dynamic web project
- Click on next => and give MyFirstJsp as project name.
- Click on Next=> click next here select generate xml deployment descriptor check box
- And click on finish.
- So now project will be created and with default xml file.
- <?xml version="1.0" encoding="UTF-8"?>
- <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javae
- /web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
- http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
- <display-name>MyFirstJsp</display-name>
- <welcome-file-list>
- <welcome-file>index.html</welcome-file>
- <welcome-file>index.htm</welcome-file>
- <welcome-file>index.jsp</welcome-file>
- <welcome-file>default.html</welcome-file>
- <welcome-file>default.htm</welcome-file>
- <welcome-file>default.jsp</welcome-file>
- </welcome-file-list>
- </web-app>
Step 3: Create a JSP page
- Right click on web content folder and select new => JSP file => give index.jsp
Step 4 : Edit Jsp page
- Edit the JSP page and give Page title and in the body section create one paragraph tag and write some text like Hello world.
- <%@ 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.or
- /TR/html4/loose.dtd">
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
- <title>Welcome</title></head>
- <body>
- <p>Hello World</p>
- </body>
- </html>
Step 5: Run dynamic web project using tomcat server
- So index.jsp is present in welcome file list of web.xml file then whenever server starts it loads welcome file i.e index.jsp
- We can give any name t our jsp but it should present in web.xml as welcome file
- <welcome-file>index.htm</welcome-file> . no need of other files which names are created by default we can delete those things.
- Right click on the project and => run as
=> run on server=> select tomcat version = >add our project if not added click on finish.
No comments