Create JSP Page in Eclipse

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:

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"
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
    <% out.print("hello to Javabeat");%>
     <p>Today's date: <%= (new java.util.Date())%></p>


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


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:

Figure 10: Output

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

Leave a Reply

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

Pin It on Pinterest

Share This

Share this post with your friends!