Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Displaying date in text box  RSS feed

 
Vijay Chandran
Ranch Hand
Posts: 186
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 959
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It should be something like this.
 
Gobinath Manoj
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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>
 
Vijay Chandran
Ranch Hand
Posts: 186
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 65830
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Freddy Wong
Ranch Hand
Posts: 959
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!