tags:

views:

454

answers:

3

This was my line in demo.jsp demo

Hello there!!! The time is <%= new java.util.Date()%>

which when i opened in firefox doesn't show the time. instead displays the same line: "The time is <%= new java.util.Date()%>"

A: 

If you go to this link, it has examples, with source, that show you how to do it properly. See the "Date" example under JSP 1.2 examples.

Another recommendation: Learn JSTL and use its format tags to format time and date properly. Don't use scriptlets.

duffymo
A: 

It looks like you're putting <%= new java.util.Date()%> in the wrong place, and it is being treated as text rather than code, it should look something like this:

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


<%= new java.util.Date() %>
</font></b></td>

If you post a code sample, it'll help a lot.

Some examples here too: http://www.roseindia.net/jsp/jsp_date_example.shtml

Dave

Dave
A: 

I'm assuming that your JSPs are compiling.

The <%= %> notation implicitly invokes the instance's toString() method. Since constructors in Java don't return a reference to the newly created instance, you're trying to do this:

new java.util.Date().toString() //! illegal

Try this instead:

<% java.util.Date now = new java.util.Date() %>
<%= now %>
James Tikalsky