File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes Displaying date in text box Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Displaying date in text box" Watch "Displaying date in text box" New topic
Author

Displaying date in text box

Vijay Chandran
Ranch Hand

Joined: Jan 07, 2007
Posts: 178
Dear friends,

I want to display the current system date in a text box present in the JSP whenever that JSP is loaded.

I tried the following
<input type="text" maxlength="9" size="" name="fromDate" value="<%out.print(new Date()); %>">

but the value is not getting displayed.
Kindly provide your help.

Regards,
Vijay
Freddy Wong
Ranch Hand

Joined: Sep 11, 2006
Posts: 959

It should be something like this.


SCJP 5.0, SCWCD 1.4, SCBCD 1.3, SCDJWS 1.4
My Blog
Gobinath Manoj
Greenhorn

Joined: Oct 17, 2007
Posts: 11
Hi

You just import util package in jsp file then you will getting the current date and time of the system. The code like ,


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

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>

<h1>PRINT CURRENT SYATEM DATE</h1>

<%//Date date=new Date();%>
<br>
<br>
<br>

date :<input type="text" value="<%= new Date()%>">

</body>
</html>


Thanks Regards <br />Gobinath.L
Vijay Chandran
Ranch Hand

Joined: Jan 07, 2007
Posts: 178
Dear Freddy,

It is not working. I set the system date values in an ActionForm and tried to display it in JSP. But still it doesn't work.



How to resolve?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61092
    
  66

You are not paying attention to the code examples people are showing you. out.print should rarely be used in JSP pages.
[ November 27, 2007: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Freddy Wong
Ranch Hand

Joined: Sep 11, 2006
Posts: 959

You can't use out.println() to display the value in the input text. It's a bit different from a language like php where you can just embed the PHP script inside HTML. You need to use <%= someObject.getCurrentDateTime() %>. Remember,
there's an equal sign after the percentage sign and there's no semicolon. Scriptlet is rarely used nowadays and it's considered a bad practice to use it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Displaying date in text box