You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Benin Technologies <be...@yahoo.fr> on 2013/01/26 00:56:07 UTC

jsp:getProperty not working

Hi,

I'm new to Tomcat/JSP

I have a JSP page that instantiates a bean, then it access the bean 
through a scriptlet, it works fine. But when I replace the scriptlet by 
a <jsp:getProperty.. tag, it doesn't work

Take my code below :
<%= employee.getFirstName() %> IS WORKING, it displays the employee's 
firstname
<jsp:getProperty name="employee" property="firstName" />  IS NOT 
WORKING, displays nothing

any idea why ?



<jsp:useBean id="employee" class="org.company.beans.EmployeeBean" 
scope="request" />
<html><body>
<%
Vector<EmployeeBean> v =(Vector<EmployeeBean>)request.getAttribute("list");
Iterator i = v.iterator();
int j = 0;
while (i.hasNext()) {
     employee = (EmployeeBean)i.next();
     %>

<%= employee.getFirstName() %>                                          
               WORKS
<jsp:getProperty name="employee" property="firstName" />         DOESN'T 
WORK !! WHY ?

<%
}
%>
</body></html>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: jsp:getProperty not working

Posted by Benin Technologies <be...@yahoo.fr>.
thanks for your reply

below my EmployeeBean source code

package org.company.beans;

public class EmployeeBean {
     private int id;
     private String    firstName,
                             lastName,
                             email,
                             department;

     public EmployeeBean(int id) {
         this.id = id;
         firstName = "";
         lastName = "";
         email = "";
         department = "";
     }

     public EmployeeBean() {
         this(0);
     }

     public int getId() {
         return id;
     }

     public void setFirstName(String firstName) {
         this.firstName = firstName;
     }
     public String getFirstName() {
         return firstName;
     }

     public void setLastName(String lastName) {
         this.lastName = lastName;
     }
     public String getLastName() {
         return lastName;
     }

     public void setEmail(String email) {
         this.email = email;
     }
     public String getEmail() {
         return email;
     }

     public void setDepartment(String department) {
         this.department = department;
     }
     public String getDepartment() {
         return department;
     }
}

Le 26/01/2013 02:10, Christopher Schultz a écrit :
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA256
>
> To whom it may concern,
>
> On 1/25/13 6:56 PM, Benin Technologies wrote:
>> I'm new to Tomcat/JSP
>>
>> I have a JSP page that instantiates a bean, then it access the
>> bean through a scriptlet, it works fine. But when I replace the
>> scriptlet by a<jsp:getProperty.. tag, it doesn't work
>>
>> Take my code below :<%= employee.getFirstName() %>  IS WORKING, it
>> displays the employee's firstname<jsp:getProperty name="employee"
>> property="firstName" />   IS NOT WORKING, displays nothing
>>
>> any idea why ?
> Can you give us the interface for EmployeeBean? Perhaps "firstName"
> isn't a proper "Java Beans" "property" and so it can't be properly
> detected, while EmployeeBean.getFirstName works just fine.
>
> - -chris
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
> Comment: GPGTools - http://gpgtools.org
> Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/
>
> iEYEAREIAAYFAlEDLRsACgkQ9CaO5/Lv0PC8awCfTPG1cu31z0RwYeolkR+TbHy6
> /TQAniNRX2HjsPZhHyZ3EcH+2zjHHeBF
> =FOIU
> -----END PGP SIGNATURE-----
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: jsp:getProperty not working

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

To whom it may concern,

On 1/25/13 6:56 PM, Benin Technologies wrote:
> I'm new to Tomcat/JSP
> 
> I have a JSP page that instantiates a bean, then it access the
> bean through a scriptlet, it works fine. But when I replace the
> scriptlet by a <jsp:getProperty.. tag, it doesn't work
> 
> Take my code below : <%= employee.getFirstName() %> IS WORKING, it
> displays the employee's firstname <jsp:getProperty name="employee"
> property="firstName" />  IS NOT WORKING, displays nothing
> 
> any idea why ?

Can you give us the interface for EmployeeBean? Perhaps "firstName"
isn't a proper "Java Beans" "property" and so it can't be properly
detected, while EmployeeBean.getFirstName works just fine.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iEYEAREIAAYFAlEDLRsACgkQ9CaO5/Lv0PC8awCfTPG1cu31z0RwYeolkR+TbHy6
/TQAniNRX2HjsPZhHyZ3EcH+2zjHHeBF
=FOIU
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: jsp:getProperty not working

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Benin,

On 1/25/13 6:56 PM, Benin Technologies wrote:
> I'm new to Tomcat/JSP
> 
> I have a JSP page that instantiates a bean, then it access the
> bean through a scriptlet, it works fine. But when I replace the
> scriptlet by a <jsp:getProperty.. tag, it doesn't work
> 
> Take my code below : <%= employee.getFirstName() %> IS WORKING, it
> displays the employee's firstname <jsp:getProperty name="employee"
> property="firstName" />  IS NOT WORKING, displays nothing
> 
> any idea why ?
> 
> 
> 
> <jsp:useBean id="employee" class="org.company.beans.EmployeeBean" 
> scope="request" /> <html><body> <% Vector<EmployeeBean> v
> =(Vector<EmployeeBean>)request.getAttribute("list"); Iterator i =
> v.iterator(); int j = 0; while (i.hasNext()) { employee =
> (EmployeeBean)i.next(); %>
> 
> <%= employee.getFirstName() %>
>  WORKS <jsp:getProperty name="employee" property="firstName" />
> DOESN'T WORK !! WHY ?
> 
> <% } %> </body></html>

Is that the full JSP? It looks like you may have your bean "employee"
in the request scope, and you haven't set a first name. Your loop may
use a page-scoped bean (or really not a scoped bean at all -- you
appear to be simply using inline scriptlets).

Try using <c:foreach> instead of writing a scriptlet for your loop.

What version of Tomcat are you using?

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iEYEAREIAAYFAlEGkuQACgkQ9CaO5/Lv0PBQ/ACgj6GheM51mjoYSx8rrcqVfiD4
kwsAn14hemCRA9Dr4nGkvI9VxFaB0EmU
=gFh0
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org