In my jsp I am using <jsp:getProperty> to get the value of a bean Here is the code sample <jsp:useBean id="test" scope="session" class="TestBean"/> <tr> <td width="60%" align="right"><b><font color="#000080">First Name #</font></b> </td> <td width="40%"><input type="text" name="fName" size="20" value="<jsp:getProperty name="test" property="firstName" />"></td> </tr>
I try to use the <jsp:getProperty> tag to get the value but it keeps initiating a "blank" bean. As a temporary workaround, I am using <% out.println(TestBean.getFirstName()) %> to achieve the same effect and it works. Ideally, I would like to use <jsp:getProperty name="beanName" property="beanID"> And some reason its not working The firstName is declared as a variable in a Bean and and it also has a corresponding get method Guru's Please help me
Your examples are a tad confusing. In your first example (the one that doesn't work), you refer to the bean with an id of test. In your second (the scriptlet example), you use TestBean which is the class name. What's up with that? Is getFirstName() a class (static) method?
No Its not a static method. Sorry for creating any confusion. I am creating instance of TestBean class TestBean testBean= new TestBean(); and trying to get the value like this <% out.println(testBean.getFirstName()) %> Thanks Maria
try instead using the <jsp:useBean id-"test".../> first and then try to acces it via the scriplet code like thgis <%= test.getFirstName()%> and see what result it gives you. That won't work. The "usebean" tag creates an object and stores it in the named context. It does not create a scriptlet variable. Likewise, just creating a scriptlet variable does not create or affect session beans. To access a "usebean" object from a scriptlet you need to do something more like:
Thank you so much for your help. I use <jsp:getProperty> in all of my JSP and it just works fine. I am having this problem only when jsp property name(count) is different from text box name(myName) for example
In all other JSP jsp propery name and text box name are the same ex <jsp:useBean id="mine" scope="session" class="examples.MyBean" /> <% out.println(mine.getCount()); %> <%= mine.getCount() %> <input type="text" name="count" size="100" value="<jsp:getProperty name="mine" property="count" /> According to me it should not make any difference. But some reason it is not working Please help Thanks in advance Maria