• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Type coversions

 
Jayii Young
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
According to JSP spec. page74 <jsp:setProperty>
"...
Properites in a Bean can be set from..., or from a computed request-time expression. ...
When assigning from a value given as a request-time attribute, no type conversions are applied, as indicated in Section JSP.2.13.2.3
..."
And I tried the following code:
my JSP page:
....
<jsp:useBean id='test' scope='page' class='Test.testProperty' type ='Test.testProperty'/>
<%int i=124;%>
<jsp:setProperty name="test" property="int_type" value="<%=i+1 %>"/>
The parameter is <jsp:getProperty name="test" property="int_type" />
...
my bean class:
....
public void setInt_type(int int_type){
this.int_type= int_type;
}
public int getInt_type(){
return int_type;
...
I tested the code agaist Tomcat, it works fine, the Jsp page output: The parameter is 125
Why is the type conversion applied in this case? Can someone give an explaination? Thanks.
 
yi zhu
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no type conversion here!
If the type of int_type is String, you will get an error...
 
Vedhas Pitkar
Ranch Hand
Posts: 445
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Type conversion will be applicable if you do something like:
String i="100";
& then
<jsp:setProperty name="test" property="int_type" value="<%=i%>"/>
As the value is a request time expression,type conversion from String to int wont happen & ou will get an error like:
Cant convert java.lang.String to int
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic