Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question about include

 
Win Yu
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have two JSP files. Even I did not put "<jsp:useBean id="worker2" class="com.wrox.projsp.ch07.BabyGameWorker2" scope="request" />" at the begining in the second file, it works, WHY??
first file :
------------
<html>
<head><title>Baby Game - Your Guesses</title></head>
<body bgcolor="#FFFFFF">
<%@ page language="java" buffer="8k" %>
<jsp:useBean id="worker2" class="com.wrox.projsp.ch07.BabyGameWorker2" scope="request" />
<jsp:setProperty name="worker2" property="*" />
<jsp:include page="/web/mediatorcompositeview/compositeinclude.jsp" flush="true" />
</body>
</html>
----------------------------------------------------
second file:compositeinclude.jsp
<!-- <jsp:useBean id="worker2" class="com.wrox.projsp.ch07.BabyGameWorker2" scope="request" /> -->
I did not put use bean at the begining.
<%@ include file="nestedheader.html" %>
<% if(worker2.validate()) {
worker2.store();
%>
<br>
<jsp:getProperty name="worker2" property="guesser" />, your choices have
been stored.<br> Here they are:<br>
<table border cols=5 width="75%" >
<caption></caption>
<tr>
<td><jsp:getProperty name="worker2" property="gender" /></td>
<td><jsp:getProperty name="worker2" property="pounds" /> lbs
<jsp:getProperty name="worker2" property="ounces" /> oz</td>
<td><jsp:getProperty name="worker2" property="month" />
<jsp:getProperty name="worker2" property="day" /></td>
<td><jsp:getProperty name="worker2" property="length" /> inches</td>
</tr>
</table>
<br>
<% } else { %>
<br> There where some choices that were not selected.<br><br>
Sorry, but you must complete all selections to play.<br>
<font size=-1>(Please hit the browser 'back' button to continue)</font><br>
%>
<% } %>
[This message has been edited by Win Yu (edited November 15, 2001).]
[This message has been edited by Win Yu (edited November 15, 2001).]
 
ruijin yang
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Win,
I think the bean's scope is "request".The included page belongs
to same request as the including page.So it works.If you change
scope to "page".I do not think it works again.You try it.
ruijin yang
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It works because you are using an include directive, which works much like the #include which we all know and love from the C preprocessor. Both files are merged into one compilation unit.
Try changing it into a dynamic include action (<jsp:include>) .
- Peter
[ April 10, 2002: Message edited by: Peter den Haan ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic