Create JSP Page in Eclipse

SHARE & COMMENT :

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

Comments

comments

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.

Speak Your Mind

*

Close
Please support the site
By clicking any of these buttons you help our site to get better