The first JSP
Java Server Page is a web page document that integrate Java codes to generate a dynamic content. In this tutorial we will create a simple JSP that show the current time.
Open
Eclipse, create a
Dynamic Web Project, name it
jsplabs and set
Target runtime as
Apache Tomcat v7.0.
Right click on the WebContent folder, select New→JSP file.
Name it
first.jsp and click
Finish
Insert the following codes between the
<body> tags:
<h1>Fist JSP</h1>
<ul>
<li>Current time: <%= new java.util.Date() %>
<li>Server: <%= application.getServerInfo() %>
<li>Session ID: <%= session.getId() %>
</ul>
Save the file.
Right click on the first.jsp file, select Run As→Run on Server.
Select your
Tomcat server and click on
Finish.
-
Exercises
Play with some other functions, such as: application.getContextPath(); session.getCreationTime(); request.getRemoteHost(); request.getServerName(); request.getServerPort(); request.getContextPath(); request.getRemoteHost().
View some system property by using function: System.getProperty(“PROPERTY_NAME”). Replace PROPERTY_NAME by os.name, user.name, user.home, user.dir, user.timezone, java.home, java.version.
Back to top