Thursday, October 2, 2008

Date Example in JSP

Till now you learned about the JSP syntax, now I will show you how to create a simple dynamic JSP page that prints the current date and time. So the following code accomplish this:

<%@page contentType="text/html" import="java.util.*" %>




"center">

"0" cellpadding="0" cellspacing
=
"0" width="460" bgcolor="#EEFFCA">






"100%">"6" color
=
"#008000"> Date Example
"100%"> Current Date
and time is:
"#FF0000">


<%= new java.util.Date() %>





The heart of this example is Date() function of the java.util package which returns the current data and time.

In the JSP Declaratives

<%@page contentType="text/html" import="java.util.*" %>

we are importing the java.util package and following JSP Expression code

<%= new java.util.Date() %>

prints the current date on the page.