<%@ page import="beans.NameBean"  %>
<%@ include file="../../demoUtil.jsp" %>

<jsp:useBean id="pageBean" class="beans.NameBean" scope="page" />
<jsp:setProperty name="pageBean" property="*" /> 

<jsp:useBean id="sessionBean" class="beans.NameBean" scope="session" />
<jsp:setProperty name="sessionBean" property="*"  />

<%-- When setProperty tag is nested in the useBean tag with session scope, 
     the bean with the new property value will be saved in the session, 
     and serialized, making the jsp distributable. But here, we cannot 
     have the setProperty nested, so for distributability we must set 
     the bean in the session ourselves, causing serialization with the
     new property value. --%>
<%
session.setAttribute("sessionBean", sessionBean);
%>

<HTML>
<HEAD> <TITLE> The UseBean JSP </TITLE> </HEAD>
<BODY BGCOLOR=white>

<H3> Welcome to the UseBean JSP </H3>
<P><B>Page bean: </B>
<% if (pageBean.getNewName().equals("")) { %>
  I don't know you. 
<% } else { %>
  Hello <%= util.HTMLReplace(pageBean.getNewName()) %> !
<%  } %> 
  
<P><B>Session bean: </B>
<% if (sessionBean.getNewName().equals("")) { %>
  I don't know you either. 
<% } else {
          if ((request.getParameter("newName") == null) ||
             (request.getParameter("newName").equals(""))) 

          { %>
         Aha, I remember you.   
<%     } %>   
       You are <%= util.HTMLReplace(sessionBean.getNewName()) %>.
<% } %>

<P>May we have your name?
<FORM METHOD=get>
<INPUT TYPE=TEXT name=newName size = 20>
<INPUT TYPE=SUBMIT VALUE="Submit name">
</FORM>
</BODY>
</HTML>
