Java beans question

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Alien
    New Member
    • Sep 2007
    • 61

    Java beans question

    Hi Guys,

    I am learning JavaBeans and while playing around with the <jsp setProperty> and <jsp getProperty>, I wanted to try something out.

    Basically the the bean class has attributes, name, address, postcode...simp le one just for demonstration with accessors and mutators as usual.

    Code:
    <%@page import="java.io.*"%>
    <%@page import="dca.address.AddressBean"%>
    
    <jsp:useBean id="myAddrBean" class="dca.address.AddressBean" scope="session" />
    
    <% myAddrBean.clear(); %>
    
    
    <html>
    <head><title>UTS/IT - JSP Tutorials</title></head>
    <body>
    
    
    <center>
    <form method="post" action="addressinput2.jsp">
      <table>
       <tr>
        <td><b>Enter your name:</b></td>
        <td><input type="text" name="yourname" size="20"></td>
       </tr>
      </table><br />
    <input type="submit" value="Goto Next Page &gt;&gt;">
    </form>  
    
    
    <%@include file="footer.jsp" %>
    Footer just displays what you have typed. Idea of this exercise is to show beans can use be used to keep track of session.


    in the 2nd one, we display the output and prompt for next input...
    Code:
    <%@page import="java.io.*"%>
    <%@page import="dca.address.AddressBean"%>
    
    <jsp:useBean id="myAddrBean" class="dca.address.AddressBean" scope="session" />
    
    
    <jsp:setProperty name="myAddrBean" property="name" param="yourname" />
      
    
    <html>
    <head><title>UTS/IT - JSP Tutorials</title></head>
    <body>
    
    
    <center>
    <form method="post" action="addressinput3.jsp">
      <table>
       <tr>
        <td><b>Enter your street address:</b></td>
        <td><input type="text" name="street" size="20"></td>
       </tr>
      </table><br />
    <input type="submit" value="Goto Next Page &gt;&gt;">
    </form>  
    
    
    <%@include file="footer.jsp" %>
    My Question is that in line 7 of addressinput2.j sp, if I substitute param="yourname " to something say "55"....jus t randomly, It should put that value in footer instead of what i have typed in addressinput1.j sp.

    When I run it, that field is just null as before. Does it mean that setProperty only takes input from html form and doesn't take other mockup values?

    Cheers
  • sumittyagi
    Recognized Expert New Member
    • Mar 2007
    • 202

    #2
    try to include footer.jsp using <jsp:include tag.

    Comment

    Working...