Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt on jsp

 
Padma priya Gururajan
Ranch Hand
Posts: 437
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Given the class:
1. package biz.mybiz;
2. public class BeanX{
3. private String a,b,c;
4. public BeanX() { a="A";b="B",c="C";}
5. public void setA(String a) { this.a=a;}
6. public void setB(String b) { this.b=b;}
7. public void setC(String c) { this.c=c;}
8. public String getAll() { return a+b+c;}
9. }

and the JSP:

1.<jsp:useBean id="x" class="biz.mybiz.BeanX" />
2.<jsp:setProperty name="x" property="*" />
3.<jsp:getProperty name="x" property="all" />
4.<jsp:setProperty name="x" property="a" param="b" />
5.<jsp:setProperty name="x" property="b" param="c" />
6.<jsp:setProperty name="x" property="c" param="a" />
7.<jsp:getProperty name="x" property="all" />
What will be generated by the Jsp when invoked with the query string a=X&b=Y&c=Z?

The answer is XYZ YZX. Can anyone explain as to how they have arrived at the answer?

With regards,
Padma priya N.G.
 
priyanka kumari
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

To set the property of the bean at runtime we use param attribue.The mechanism for performing this automatic mapping of query parameters to bean attributes is to we make use of the * wildcard for the property attribute of the setProperty tag. This will set the propeties one after the other as given in the query string so we get first result as XYZ.
For the second result we explicitly set the values of the properties in the tag hence the result YZX.

Thanks
Priyanka
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic