Creating and Executing JSP


The following are the steps for creating and executing JSP in tomcat using eclipse IDE.



  • Create a new Tomcat Project as we have done in previous step. Now select TomcatProject in the workspace and right click on it then select New > File. Give the file name JSPDemo.jsp and click Finish.




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

 



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




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




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


                    

Copyright © 2010 VisualBuilder. All rights reserved