• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Martians and c:set - is it possible?

 
Jan Sterk
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Suppose some martians landed on earth, and there is an attribute with name 'timestamp', and a bean as value. That bean has a property 'date', which is of type java.util.Date. Now suppose you want to set that property in a JSP page to the current date (i.e. new Date(); ) with c:set.

It can be done as follows:



Is it also possible without first creating the 'now'-attribute? I tried this:



but then this exception occurs:

java.lang.IllegalArgumentException: Cannot convert <% new Date(); %> of type class java.lang.String to class java.util.Date

Why is the scriplet <% new Date(); %> not evaluating to a Date object, but to a String? Is it possible, using a scriplet, to assign an object to 'value', of another type then String?

(Btw the martial thing was just to get your attention. I know it is not possible.)
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65340
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The JSTL is not designed to work with scriptlets or scriptlet expressions. You should not be mixing them.
 
Milind Patil
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have to use
 
Jan Sterk
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Milind Patil:
You have to use


That works fine!

It is strange, because I always thought that scripting expressions were translated to out.print( expr ). But not in this case, apparently.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic