• Menu
  • Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

JavaBeat

Java Tutorial Blog

  • Java
    • Java 7
    • Java 8
    • Java EE
    • Servlets
  • Spring Framework
    • Spring Tutorials
    • Spring 4 Tutorials
    • Spring Boot
  • JSF Tutorials
  • Most Popular
    • Binary Search Tree Traversal
    • Spring Batch Tutorial
    • AngularJS + Spring MVC
    • Spring Data JPA Tutorial
    • Packaging and Deploying Node.js
  • About Us
    • Join Us (JBC)
  • Java
    • Java 7
    • Java 8
    • Java EE
    • Servlets
  • Spring Framework
    • Spring Tutorials
    • Spring 4 Tutorials
    • Spring Boot
  • JSF Tutorials
  • Most Popular
    • Binary Search Tree Traversal
    • Spring Batch Tutorial
    • AngularJS + Spring MVC
    • Spring Data JPA Tutorial
    • Packaging and Deploying Node.js
  • About Us
    • Join Us (JBC)

Create JSP Page in Eclipse

January 16, 2014 //  by Krishna Srinivasan//  Leave a Comment

  • Java EE Tutorials
  • JSP Tutorials
  • Recommended Books for Java Server Pages (JSP)

Simple JSP Example using Eclipse

Let us write a simple JSP code using Eclipse IDE and execute it using a web application server (Tomcat).

Tools Used

We are using the following tools to write and execute our JSP code:

  • Java 7
  • Eclipse IDE
  • Tomcat 7

Here we are assuming that the reader is well aware of the above mentioned tools and has knowledge of installation of these tools.

Once all the above mentioned tools are installed and configured, open the Eclipse IDE. Follow the below steps to create a simple JSP file using Eclipse.

Step 1: Create a Dynamic project as shown in the image below:

jsp_dynamicproject
Figure 1: Dynamic Project Creation

Step 2: Type the project name as “HelloWorldJSP” and click Next.

jsp_projectnameFigure 2: Name the project

Step 3: Now select the checkbox “Generate web.xml deployment descriptor” and click on Finish button.

jsp_createprojectFigure 3:Finish

Step 4: Once the project is created, you can see the project structure as in the screen below:

jsp_projectstructureFigure 4:Project Structure

Step 5: Now create a JSP file under the WebContent folder as shown below:

jsp_createjspfileFigure 5:Create JSP file

Step 6: Name the file as hellojavabeat.jsp and click on Finish button.

jsp_filenameFigure 6:Give JSP file name

Step 7: Now open the file hellojavabeat.jsp and paste the below contents in it:

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!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=UTF-8">
<title>Insert title here</title>
</head>
<body>
<body>
    <% out.print("hello to Javabeat");%>
     <p>Today's date: <%= (new java.util.Date())%></p>

</body>
</html>

Here we are printing a message “hello to Javabeat” and current time using the tags which are called scriptlets. More about scriptlet will be discussed in next chapter.

Step 8: Now to execute this JSP, we need to configure a web server (in our case it is Tomcat 7). Now select the file hellojavabeat.jsp and select Run As > Run on Server as shown below:

jsp_executejspfileFigure 7:Execute JSP file

Step 9: Choose the Tomcat version on your system. In our case it is “Tomcat v7.0 Server” and click Next.

jsp_configserver1Figure 8:Configure Tomcat

Step 10:Set the Tomcat path (installed path) and click Next.

jsp_settomcatpathFigure 9: Set Tomcat Path

Step 11: Click Finish

jsp_configserver2

Step 12: Now that you have configured web server with Eclipse, now run the JSP file by selecting Run As > Run on Server. The server will be started and output as shown in the screen below opens up:

jsp_output
Figure 10: Output

Previous Tutorial : JSP Architecture and Lifecycle   ||  Next Tutorial :  JSP Syntax

Category: Java EETag: Eclipse, JSP Tutorials

About Krishna Srinivasan

He is Founder and Chief Editor of JavaBeat. He has more than 8+ years of experience on developing Web applications. He writes about Spring, DOJO, JSF, Hibernate and many other emerging technologies in this blog.

Previous Post: « What is Bootstrap?
Next Post: Bootstrap Setup »

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Follow Us

  • Facebook
  • Pinterest

FEATURED TUTORIALS

New Features in Spring Boot 1.4

Difference Between @RequestParam and @PathVariable in Spring MVC

What is new in Java 6.0 Collections API?

The Java 6.0 Compiler API

Introductiion to Jakarta Struts

What’s new in Struts 2.0? – Struts 2.0 Framework

JavaBeat

Copyright © by JavaBeat · All rights reserved
Privacy Policy | Contact