By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,175 Members | 1,710 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,175 IT Pros & Developers. It's quick & easy.

Java beans question

P: 61
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...simple one just for demonstration with accessors and mutators as usual.

Expand|Select|Wrap|Line Numbers
  1. <%@page import="java.io.*"%>
  2. <%@page import="dca.address.AddressBean"%>
  3.  
  4. <jsp:useBean id="myAddrBean" class="dca.address.AddressBean" scope="session" />
  5.  
  6. <% myAddrBean.clear(); %>
  7.  
  8.  
  9. <html>
  10. <head><title>UTS/IT - JSP Tutorials</title></head>
  11. <body>
  12.  
  13.  
  14. <center>
  15. <form method="post" action="addressinput2.jsp">
  16.   <table>
  17.    <tr>
  18.     <td><b>Enter your name:</b></td>
  19.     <td><input type="text" name="yourname" size="20"></td>
  20.    </tr>
  21.   </table><br />
  22. <input type="submit" value="Goto Next Page &gt;&gt;">
  23. </form>  
  24.  
  25.  
  26. <%@include file="footer.jsp" %>
  27.  
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...
Expand|Select|Wrap|Line Numbers
  1. <%@page import="java.io.*"%>
  2. <%@page import="dca.address.AddressBean"%>
  3.  
  4. <jsp:useBean id="myAddrBean" class="dca.address.AddressBean" scope="session" />
  5.  
  6.  
  7. <jsp:setProperty name="myAddrBean" property="name" param="yourname" />
  8.  
  9.  
  10. <html>
  11. <head><title>UTS/IT - JSP Tutorials</title></head>
  12. <body>
  13.  
  14.  
  15. <center>
  16. <form method="post" action="addressinput3.jsp">
  17.   <table>
  18.    <tr>
  19.     <td><b>Enter your street address:</b></td>
  20.     <td><input type="text" name="street" size="20"></td>
  21.    </tr>
  22.   </table><br />
  23. <input type="submit" value="Goto Next Page &gt;&gt;">
  24. </form>  
  25.  
  26.  
  27. <%@include file="footer.jsp" %>
  28.  
  29.  
  30.  
My Question is that in line 7 of addressinput2.jsp, if I substitute param="yourname" to something say "55"....just randomly, It should put that value in footer instead of what i have typed in addressinput1.jsp.

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
Sep 7 '09 #1
Share this Question
Share on Google+
1 Reply


sumittyagi
Expert 100+
P: 202
try to include footer.jsp using <jsp:include tag.
Sep 8 '09 #2

Post your reply

Sign in to post your reply or Sign up for a free account.