Results 1 to 14 of 14
  1. #1
    mmarkym is offline Member
    Join Date
    Nov 2009
    Posts
    20
    Rep Power
    0

    Default Displaying Javabean properties in a JSP

    I have a JSP page trying to display a property (record) from a Javabean. Somehow in the setRecord is not working in the JavaBean

    <%--
    Document : index
    Created on : Dec 21, 2010, 2:46:13 AM

    --%>

    <%@page contentType="text/html" pageEncoding="UTF-8" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>JSP Page</title>
    </head>
    <jsp:useBean id="eb" scope="request" class="learn.ClientBean" />
    <jsp:setProperty name="eb" property="fname" param="f" />
    <jsp:setProperty name="eb" property="lname" param="l" />
    <jsp:setProperty name="eb" property="email" param="e" />
    <jsp:getProperty name="eb" property="record" />


    <body bgcolor="#000000" text="#ffffff">
    <h1>Subscription Form</h1>

    <form action="index.jsp" method="GET" >
    <table width="30%" border="0" cellpadding="4">
    <tr>
    <td>First Name: </td>
    <td><input type="text" id="f" name="f" size="15" value="${eb.fname}"/></td>
    </tr>
    <tr>
    <tr>
    <td>Last Name: </td>
    <td><input type="text" id="l" name="l" size="15" value="${eb.lname}"/></td>
    </tr>
    <tr>
    <td>Email:</td>
    <td><input type="text" id="e" name="e" size="15" value="${eb.email}"/></td>
    </tr>
    <tr>
    <td colspan="2"><div align="center">
    <input name="Submit" type="Submit" value="Subscibe"/>
    </div></td>
    </tr>
    </table>

    <table width="30%" border="0" cellpadding="4">
    <tr>
    <td>

    (Member: ${eb.record})

    </td>
    </tr>
    </table>

    </form>

    </body>
    </html>

    -----The Javabean


    package learn;

    import java.io.Serializable;


    public class ClientBean implements Serializable {

    CustomerPurchaseOrder proxy;

    private String _fname;
    private String _lname;
    private String _email;
    private String _record;

    public ClientBean()
    {



    }//end constructor



    public void setFname(String fname)
    {
    _fname = fname;
    }

    public String getFname()
    {
    return _fname;
    }

    public void setLname(String lname)
    {
    _lname = lname;

    }

    public String getLname()
    {
    return _lname;
    }


    public void setEmail(String Email)
    {
    _email = Email;
    }

    public String getEmail()
    {
    return _email;
    }


    public void setRecord()
    {

    CustomerPurchaseOrderService service = new CustomerPurchaseOrderService();
    proxy = service.getCustomerPurchaseOrderPort();

    _record = "Test";

    //_record = proxy.createMember(_fname, _lname, _email);

    }

    public String getRecord()
    {

    return _record;

    }


    }//end class




    mark

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

    Default

    <jsp:getProperty name="eb" property="record" />

    That's a get, not a set.

  3. #3
    mmarkym is offline Member
    Join Date
    Nov 2009
    Posts
    20
    Rep Power
    0

    Default

    It's a get because I want to set the property, _record, in the JavaBean. I then want to retrieve it from the JSP page. This is why I use the getProperty

    mark

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

    Default

    Except the getProperty calls (unsurprisingly) the getRecord() method.

    Nothing in that JSP calls the setRecord() method, so it never gets set.

  5. #5
    mmarkym is offline Member
    Join Date
    Nov 2009
    Posts
    20
    Rep Power
    0

    Default

    I've added a setProperty for record in the JSP page.

    Javabean-


    package learn;

    import java.io.Serializable;


    public class ClientBean implements Serializable {

    CustomerPurchaseOrder proxy;

    private String _fname;
    private String _lname;
    private String _email;

    private String _record;

    public ClientBean()
    {



    }//end constructor



    public void setFname(String fname)
    {
    _fname = fname;
    }

    public String getFname()
    {
    return _fname;
    }

    public void setLname(String lname)
    {
    _lname = lname;

    }

    public String getLname()
    {
    return _lname;
    }


    public void setEmail(String Email)
    {
    _email = Email;
    }

    public String getEmail()
    {
    return _email;
    }


    public void setRecord()
    {

    WS service = new WS();
    _record = service.createMember(_fname, _lname, _email);

    }

    public String getRecord()
    {

    return _record;

    }


    }//end class


    JSP page

    <%--
    Document : index
    Created on : Dec 21, 2010, 2:46:13 AM

    --%>

    <%@page contentType="text/html" pageEncoding="UTF-8" import="learn.*"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>JSP Page</title>
    </head>
    <jsp:useBean id="eb" scope="request" class="learn.ClientBean" />
    <jsp:setProperty name="eb" property="fname" param="f" />
    <jsp:setProperty name="eb" property="lname" param="l" />
    <jsp:setProperty name="eb" property="email" param="e" />
    <jsp:setProperty name="eb" property="record" />



    <body bgcolor="#000000" text="#ffffff">
    <h1>Subscription Form</h1>

    <form action="index.jsp" method="GET" >
    <table width="30%" border="0" cellpadding="4">
    <tr>
    <td>First Name: </td>
    <td><input type="text" id="f" name="f" size="15" value="${eb.fname}"/></td>
    </tr>
    <tr>
    <tr>
    <td>Last Name: </td>
    <td><input type="text" id="l" name="l" size="15" value="${eb.lname}"/></td>
    </tr>
    <tr>
    <td>Email:</td>
    <td><input type="text" id="e" name="e" size="15" value="${eb.email}"/></td>
    </tr>
    <tr>
    <td colspan="2"><div align="center">
    <input name="Submit" type="Submit" value="Subscibe"/>
    </div></td>
    </tr>
    </table>

    <table width="30%" border="0" cellpadding="4">
    <tr>
    <td>
    <%

    eb.setRecord();

    %>

    (Member: ${eb.record})

    </td>
    </tr>
    </table>

    </form>

    </body>
    </html>

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

    Default

    Can you use code tags please?

    Anyway, that won't work since your setter is wrong (as far as beans are concerned). They have a parameter, so this won't work since setProperty will expect a method with a String parameter...and will also expect something in the request called "record".

    I suspect you'll have to manually call setRecord() yourself. Which I see you have done later in the JSP page.

  7. #7
    mmarkym is offline Member
    Join Date
    Nov 2009
    Posts
    20
    Rep Power
    0

    Default

    Now I've added some params to the setRecord method.

    Java Code:
    <%-- 
        Document   : index
        Created on : Dec 21, 2010, 2:46:13 AM
       
    --%>
    
    <%@page contentType="text/html" pageEncoding="UTF-8" import="learn.*"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
       "http://www.w3.org/TR/html4/loose.dtd">
    
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title>JSP Page</title>
        </head>
        <jsp:useBean id="eb" scope="request" class="learn.ClientBean" />
        <jsp:setProperty name="eb" property="fname" param="f" />
        <jsp:setProperty name="eb" property="lname" param="l" />
        <jsp:setProperty name="eb" property="email" param="e" />
        <jsp:setProperty name="eb" property="record" param="f, l, e" />
        <jsp:getProperty name="eb" property="record"/>
    
        
        <body bgcolor="#000000" text="#ffffff">
            <h1>Subscription Form</h1>
    
            <form action="index.jsp" method="GET" >
        <table width="30%" border="0" cellpadding="4">
          <tr>
            <td>First Name: </td>
            <td><input type="text" id="f" name="f" size="15" value="${eb.fname}"/></td>
          </tr>
          <tr>
              <tr>
            <td>Last Name: </td>
            <td><input type="text" id="l" name="l" size="15" value="${eb.lname}"/></td>
          </tr>
          <tr>
            <td>Email:</td>
            <td><input type="text" id="e" name="e" size="15" value="${eb.email}"/></td>
          </tr>
          <tr>
            <td colspan="2"><div align="center">
              <input name="Submit" type="Submit" value="Subscibe"/>
            </div></td>
          </tr>
        </table>
    
          <table width="30%" border="0" cellpadding="4">
              <tr>
                  <td>
                      <%
                      
                      eb.setRecord(eb.getFname(), eb.getLname(), eb.getEmail());
    
                      out.println(eb.getRecord());
    
                      %>
                                                                                       
                  </td>
              </tr>
          </table>
    
    </form>
    
        </body>
    </html>
    Java Bean-


    Java Code:
    package learn;
    
    import java.io.Serializable;
    
    
    public class ClientBean implements Serializable {
    
       CustomerPurchaseOrder proxy;
       
       private String _fname;
       private String _lname;
       private String _email;
    
       private String _record;
    
        public ClientBean()
        {
    
              
    
        }//end constructor
    
    
    
        public void setFname(String fname)
        {
            _fname = fname;
        }
    
        public String getFname()
        {
            return _fname;
        }
    
        public void setLname(String lname)
        {
            _lname = lname;
    
        }
    
        public String getLname()
        {
            return _lname;
        }
    
    
            public void setEmail(String Email)
        {
            _email = Email;
        }
    
            public String getEmail()
        {
            return _email;
        }
    
            
        public void setRecord(String fn, String ln, String em)
             {
    
               WS service = new WS();
               _record = service.createMember(fn, ln, em);
    
               
    
             }
    
        public String getRecord()
             {
    
                return _record;
    
             }
    
    }//end class

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

    Default

    And?
    Not that you actually needed the parameters.

    And this:
    Java Code:
    <jsp:getProperty name="eb" property="record"/>
    is still pointless.

  9. #9
    mmarkym is offline Member
    Join Date
    Nov 2009
    Posts
    20
    Rep Power
    0

    Default

    Seems like it should work. I'm new to JSP so any help is well apreciated.

    index.jsp-
    Java Code:
    <%-- 
        Document   : index
        Created on : Dec 21, 2010, 2:46:13 AM
       
    --%>
    
    <%@page contentType="text/html" pageEncoding="UTF-8" import="learn.*"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
       "http://www.w3.org/TR/html4/loose.dtd">
    
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title>MyJSP</title>
        </head>
        <jsp:useBean id="eb" scope="request" class="learn.ClientBean" />
        <jsp:setProperty name="eb" property="fname" param="f" />
        <jsp:setProperty name="eb" property="lname" param="l" />
        <jsp:setProperty name="eb" property="email" param="e" />
        <jsp:setProperty name="eb" property="record" />
        
    
        
        <body bgcolor="#000000" text="#ffffff">
            <h1>Subscription Form</h1>
    
            <form action="index.jsp" method="GET" >
        <table width="30%" border="0" cellpadding="4">
          <tr>
            <td>First Name: </td>
            <td><input type="text" id="f" name="f" size="15" value="${eb.fname}"/></td>
          </tr>
          <tr>
              <tr>
            <td>Last Name: </td>
            <td><input type="text" id="l" name="l" size="15" value="${eb.lname}"/></td>
          </tr>
          <tr>
            <td>Email:</td>
            <td><input type="text" id="e" name="e" size="15" value="${eb.email}"/></td>
          </tr>
          <tr>
            <td colspan="2"><div align="center">
              <input name="Submit" type="Submit" value="Subscibe"/>
            </div></td>
          </tr>
        </table>
    
          <table width="30%" border="0" cellpadding="4">
              <tr>
                  <td>
                      <%
                      
                      eb.setRecord();
    
                      out.println(eb.getRecord());
    
                      %>
                                                                                       
                  </td>
              </tr>
          </table>
    
    </form>
    
        </body>
    </html>
    JavaBean-

    Java Code:
    package learn;
    
    import java.io.Serializable;
    
    
    public class ClientBean implements Serializable {
    
       CustomerPurchaseOrder proxy;
       
       private String _fname;
       private String _lname;
       private String _email;
    
       private String _record;
    
        public ClientBean()
        {
    
              
    
        }//end constructor
    
    
    
        public void setFname(String fname)
        {
            _fname = fname;
        }
    
        public String getFname()
        {
            return _fname;
        }
    
        public void setLname(String lname)
        {
            _lname = lname;
    
        }
    
        public String getLname()
        {
            return _lname;
        }
    
    
            public void setEmail(String Email)
        {
            _email = Email;
        }
    
            public String getEmail()
        {
            return _email;
        }
    
            
        public void setRecord()
             {
    
               WS service = new WS();
               _record = service.createMember(_fname, _lname, _email);
    
               
    
             }
    
        public String getRecord()
             {
    
                return _record;
    
             }
    
    }//end class

  10. #10
    mmarkym is offline Member
    Join Date
    Nov 2009
    Posts
    20
    Rep Power
    0

    Default

    The error is-

    org.apache.jasper.JasperException: PWC6053: Can't find a method to write property 'record' of type 'java.lang.String' in a bean of type 'learn.ClientBean'

  11. #11
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

    Default

    Yes, because this
    <jsp:setProperty name="eb" property="record" />

    is you telling the JSP engine that you want it to call the setRecord() method (that is a Java Bean method, which takes a parameter of class the same as the record attribute, ie a String), passing in a parameter from the request that has the name "record". You neither have a setRecord(String) method, nor a parameter "record" in the request.

    As I said, since you are calling setRecord() manually (which should have no parameters as they are simply the values held in the bean anyway) there is no need for this setProperty tag at all.

    In fact, why setRecord at all? Why not simply do all this in getRecord? If _record is null then make the call to set it, then return _record.

  12. #12
    mmarkym is offline Member
    Join Date
    Nov 2009
    Posts
    20
    Rep Power
    0

    Default

    Ok. This is producing a page not found. It could be close.

    index.jsp-
    Java Code:
    <%-- 
        Document   : index
        Created on : Dec 21, 2010, 2:46:13 AM
       
    --%>
    
    <%@page contentType="text/html" pageEncoding="UTF-8" import="learn.*"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
       "http://www.w3.org/TR/html4/loose.dtd">
    
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title>MyJSP</title>
        </head>
        <jsp:useBean id="eb" scope="request" class="learn.ClientBean" />
        <jsp:setProperty name="eb" property="fname" param="f" />
        <jsp:setProperty name="eb" property="lname" param="l" />
        <jsp:setProperty name="eb" property="email" param="e" />
              
        <body bgcolor="#000000" text="#ffffff">
            <h1>Subscription Form</h1>
    
            <form action="index.jsp" method="GET" >
        <table width="30%" border="0" cellpadding="4">
          <tr>
            <td>First Name: </td>
            <td><input type="text" id="f" name="f" size="15" value="${eb.fname}"/></td>
          </tr>
          <tr>
              <tr>
            <td>Last Name: </td>
            <td><input type="text" id="l" name="l" size="15" value="${eb.lname}"/></td>
          </tr>
          <tr>
            <td>Email:</td>
            <td><input type="text" id="e" name="e" size="15" value="${eb.email}"/></td>
          </tr>
          <tr>
            <td colspan="2"><div align="center">
              <input name="Submit" type="Submit" value="Subscibe"/>
            </div></td>
          </tr>
        </table>
    
          <table width="30%" border="0" cellpadding="4">
              <tr>
                  <td>
                      <%
                      
                          out.println(eb.getRecord());
    
                      %>
                                                                                       
                  </td>
              </tr>
          </table>
    
    </form>
    
        </body>
    </html>
    JavaBean-


    Java Code:
    package learn;
    
    import java.io.Serializable;
    
    
    public class ClientBean implements Serializable {
    
       CustomerPurchaseOrder proxy;
       
       private String _fname;
       private String _lname;
       private String _email;
    
       private String _record;
    
        public ClientBean()
        {
    
              
    
        }//end constructor
    
    
    
        public void setFname(String fname)
        {
            _fname = fname;
        }
    
        public String getFname()
        {
            return _fname;
        }
    
        public void setLname(String lname)
        {
            _lname = lname;
    
        }
    
        public String getLname()
        {
            return _lname;
        }
    
    
            public void setEmail(String Email)
        {
            _email = Email;
        }
    
            public String getEmail()
        {
            return _email;
        }
    
            
        public void setRecord()
             {        
               
    
             }
    
        public String getRecord()
             {
    
                WS service = new WS();
               _record = service.createMember(_fname, _lname, _email);
    
    
                return _record;
    
             }
    
    }//end class

  13. #13
    Fsoft is offline Member
    Join Date
    Dec 2010
    Posts
    2
    Rep Power
    0

    Default

    Pal, Am having this problem of response from jsp page. The error is Bad version in .class file.

    pls help out.....

  14. #14
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,242
    Rep Power
    19

Similar Threads

  1. Clock JavaBean
    By dns.gonz in forum AWT / Swing
    Replies: 9
    Last Post: 10-08-2010, 04:49 AM
  2. JavaBean
    By hannes in forum New To Java
    Replies: 5
    Last Post: 02-14-2010, 07:51 PM
  3. components in javabean
    By NAIYYAR ALI in forum Advanced Java
    Replies: 0
    Last Post: 10-05-2009, 03:36 PM
  4. Enterprise JavaBean 3.0
    By Java Tutorial in forum Java Tutorial
    Replies: 0
    Last Post: 06-19-2008, 11:42 PM
  5. JavaBean Problem
    By Peter in forum Advanced Java
    Replies: 2
    Last Post: 07-05-2007, 01:37 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •