Win a copy of JDBC Workbook this week in the JDBC and Relational Databases forum
or A Day in Code in the A Day in Code forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

type conversions

 
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,
 
author
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?
 
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.
 
"I know this defies the law of gravity... but I never studied law." -B. Bunny Defiant tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic