• 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: 



  • 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


how to run jsp program in tomcat server eclipse



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.


  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javae
  4. /web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
  5. http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  6.   <display-name>MyFirstJsp</display-name>
  7.   <welcome-file-list>
  8.     <welcome-file>index.html</welcome-file>
  9.     <welcome-file>index.htm</welcome-file>
  10.     <welcome-file>index.jsp</welcome-file>
  11.     <welcome-file>default.html</welcome-file>
  12.     <welcome-file>default.htm</welcome-file>
  13.     <welcome-file>default.jsp</welcome-file>
  14.   </welcome-file-list>
  15. </web-app>

Step 3: Create a JSP page


run jsp on eclipse


  • 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.


  1. <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
  2.     pageEncoding="ISO-8859-1"%>
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.or
  4. /TR/html4/loose.dtd">
  5. <html>
  6. <head>
  7. <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
  8. <title>Welcome</title></head>
  9. <body>
  10. <p>Hello World</p>
  11. </body>
  12. </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. 
how to compile jsp program in tomcat

Instance Of Java

We will help you in learning.Please leave your comments and suggestions in comment section. if you any doubts please use search box provided right side. Search there for answers thank you.
«
Next
Newer Post
»
Previous
Older Post

No comments

Leave a Reply

Select Menu