IntelliJ Java IDE
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes type conversions Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Professional Certification » Web Component Certification (SCWCD/OCPJWCD)
Reply Bookmark "type conversions" Watch "type conversions" New topic
Author

type conversions

tony lee
Ranch Hand

Joined: Jan 21, 2002
Posts: 52
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,


SCJP2, SCWCD
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
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

Joined: Jan 21, 2002
Posts: 52
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

Joined: Mar 25, 2002
Posts: 93
You will have to declare the property as a String type, I suppose , so that you can use the expressions in your value attribute.


Hemant Kamat<br />SCJP2<br />SCWCD<br />SCBCD<br />SCEA-I
 
IntelliJ Java IDE
 
subject: type conversions
 
Threads others viewed
Is This a Widening or an Upcast?
Problem returning a byte (was:Why it gives Compiler error?)
widening reference conversions
Question #1 from Doug's book
Difference between BeanUtils and Propertyutils
IntelliJ Java IDE