Home | Ajax | BioInformatics | Dojo | EAI | EJB | Hibernate | J2ME | Java | Java Glossary | Java Servlets | JavaScript | Jboss | JDBC | JDO | Jmeter | JSF | JSP | JUnit | Maven | MySQL | Spring Framework | SQL | Struts | Technology | WAP | Web Services | XML
 
 
Search All Tutorials

 
Programming Tutorials: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML
 
JSP
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments

JSP date example

                          

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.*" %>

<!--

http://www.roseindia.net/jsp

-->

<html>
<body>
<p>
&nbsp;</p>
<div align=
"center">
<center>
<table border=
"0" cellpadding="0" cellspacing
=
"0" width="460" bgcolor="#EEFFCA">

<tr>
<td width=
"100%"><font size="6" color
=
"#008000">&nbsp;Date Example</font></td>

</tr>
<tr>
<td width=
"100%"><b>&nbsp;Current Date 
and time is:&nbsp;
<font color="#FF0000">


<%= new java.util.Date() %>
</font></b></td>
</tr>
</table>
</center>
</div>

</body>
</html>

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.

  Execute the example.
  Download the  code

                          

Facing Programming Problem?
Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

17 comments so far (post your own) View All Comments Latest 10 Comments:

Hi Srinivasan: you have to put your file abc.jsp into the folder webapps if you are using Tomcat. Then you have to open your browser and in the addres bar write: http://localhost:8080/abc.jsp
Hope it's what you are asking for.
Regards
Crista

Posted by Crista on Wednesday, 06.11.08 @ 04:02am | #62987

i have one form, in that i have two text box which is used to get only hours and minutes like starting and ending time s of classes(9:30 to 10:30)
after receiving that value from the form i want store it in oracle table...
by using condition i want to retrive the record set deatils which is equal to 9:30 to 10:30.....

Posted by vasanthi on Monday, 03.24.08 @ 18:02pm | #54161

i want to retrieve date fields from the database in jsp with some user condition ie
i get input from_date and to_date from the user , then i want to retrieve the records present in my database with that given dates.
plz...../

Posted by pavithra on Wednesday, 02.27.08 @ 21:01pm | #50324

how can i create a web project using jsp in myeclipse........please inform me

Posted by Ramanuja Reddy on Saturday, 02.2.08 @ 10:59am | #46950

i am really thanks this web site
this one of the devlober best site very nice roseindia.net

Posted by prakasam on Friday, 01.25.08 @ 12:34pm | #46106

Your web site is absolutely marvelous....... it has got most of the fundamentals right and its very informative....... im a employee of Ness Technologies, Banglore n am a very good reader of the articles in ur web......

Thank u......
Regards,
Abdullah khan

Posted by Abdullah khan on Tuesday, 10.23.07 @ 09:39am | #34601

I want to get the time only.
How i want to write the program.
This program show all date month year time

Posted by selestin on Tuesday, 10.16.07 @ 14:56pm | #34197

if any body ask the exact definition of web server then wat to answer can any body tell me??????/

Posted by neha on Monday, 09.17.07 @ 16:03pm | #27118

hi while compliling the same date.jsp ,im getting error for generated servlet saying that cannot access the java.lang.object bad class file with (JRE path)
along with version saying that actual version is 48.0 and file is 49.0 either select the correct subdirectory or path .

please provide me solution .

Posted by mukesh on Monday, 08.27.07 @ 11:33am | #24236

helo sri
Before compiling u must have installed apache tomcat webserver& u need to set environment variablesas follows
JAVA_HOME
(j2sdk installed folder)(i.e c:\j2sdk1.4)
CATALINA_HOME
(TOMCAT INSTALLED FOLDER)
CLASSPATH
(C:\J2SDK1.4\BIN)
select path from exising and edit it and paste the classpaths VALUE I.E C:\J2SDK1.4\BIN;
SEMICOLON IS NESSESARY IN STARTING& ENDING
----------------------------------------
NOW SAVE YOUR PROGRAM IN TOMCAT FOLDER UNDER WEBAPPS & RUN THE SERVER AND DEPLOY YOUR PROGRAM



ALL THE BEST!

Posted by reddikishsore on Wednesday, 08.22.07 @ 20:08pm | #23924

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Hot Web Programming Job

Java String toLowerCase Example
Java String toCharArray Example
Java String substring Example
Java String indexOf Example
Java String startsWith Example
Java String hashCode Example
Java String matches Example
Java String length Example
Java String lastIndexOf Example
Java String isEmpty Example
Java String equalsIgnoreCase Example
Java String equals Example
Java String endsWith Example
Java String copyValueOf Example
Java String contentEquals Example
  EAI Articles
  Java Certification
Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2007. All rights reserved.