Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

type conversions

 
tony lee
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
what's the type conversion in jsp?
i read from spec that there're two kinds of conversions: Conversions from String values & Conversions from request-time expressions. i just don't know why we use them
thanks,
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Say you have a JavaBean with an int property:and you set it inside a JSP:Now the value is really just a string in the JSP source. What the spec says is that this string will be converted to an int with the value 101.
Now considerThis time round, the value is a scriptlet evaluated at request time. Even though the result is still a String, the JSP container will not perform any of the automatic conversions and so this code won't work at all (I'd expect it to fail during the java compilation phase).
- Peter
 
tony lee
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks peter,
But from spec,Table JSP.4-2, we see:
"This (value) attribute can accept a request-time attribute expression as a value."
1) Why the last code segment you gave is wrong?
2) I now supposed you were right, how can we convert the value "101" manually in the scenario?
 
Goan Balchao
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You will have to declare the property as a String type, I suppose , so that you can use the expressions in your value attribute.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic