Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to parse values from beans??

 
Tom Barns
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All
if you we use <jsp:getProperty >action we will get a string represent that data,if i want to convert or cast that string to double or integer or something else,how do we do that.
i know there is a way to access the bean property using scriplets and do all the conversion that i need,but how do we parse or cast or convert that string which we get using that action to primitives data type or other objects if i need it.
or at least how to assign that output from that action to a variable.
thanks for your help.
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Surely if you want to assign the value from a bean to a variable, you must be doing that in a scriptlet anyway. HTML has ho concept of "variable".
If your bean has methods which return appropriate types, you can just call them:
<% int x = myBean.getCount(); %>
Am I missing something?
 
Tom Barns
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply.
i do undersdtand what you said,but can we do something like this:
<%String s=<jsp:getProperty name="name" property="count" /> %>
i know that doesn't compile,but is there anyway to assign the output of that action to a variable?
thanks again.
 
Ashwin Desai
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
No, I do not think that you could assign the value by using the <jsp:> tag. The best way is to init it as Frank has suggested.
Ashwin.
 
Tom Barns
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks,i do think so.
 
Anil Vupputuri
Ranch Hand
Posts: 527
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We can not use nested Jsp tags as it leads to compilation error.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic