STEP 8: Create and execute a JSP

 

1. Select TomcatProject (created in step 6) in the workspace and right click on it, then select New > File. Give the file name JSPDemo.jsp and click Finish.
 

2.Add the following code to the file JSPDemo.jsp and save it.

<html>
<title>JSP Demo</title>
<body bgcolor="blue" text="white">

<!-- DIRECTIVES -->
<%@ page language = "java" %>
<%@ page import = "java.util.*" %>
<%@ page contentType = "TEXT/HTML" %>

<!-- SCRIPLETS -->
<H1>
<% if (Calendar.getInstance().get(Calendar.AM_PM) == Calendar.AM)
{ %>
Good Morning !
<% } else { %>
Good Afternoon!
<% } %>
</H1>

<H2> If you're seeing this page via a web browser, it means you've integrated Tomcat and Eclipse successfully. Congratulations!</H2>

<H3> The current time is: <%out.println(new java.util.Date()); %> </H3>



</body>
</html>

3.Start Tomcat by pressing Start Tomcat button in the toolbar.

4.The log of startup of Tomcat will appear in the Eclipse console view.

5.Open a web browser and go to the URL http://localhost:8080/TomcatProject/JSPDemo.jsp . A page will load and you will get the following figure if followed all the above steps.