Tải bản đầy đủ (.pdf) (50 trang)

Tài liệu XML, XSLT, Java, and JSP: A Case Study in Developing a Web Application- P15 pptx

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (1.6 MB, 50 trang )

682
Appendix C Source Code for bonForum Web Application
<form method=”POST”
action=”/bonForum/servlet/BonForumEngine”>
<table border=”0” cellspacing=”0” cellpadding=”0”
rows=”3” cols=”1” width=”100%” bgcolor=”#00FFFF”>
<tr>
<label for=”debug”>enable debugging information:</label>
<%
String debug = “no”;
try {
debug = (String)
request.getParameter(“output_debug_info”);
if(debug == null) {
debug = “no”;
}
}
catch(java.lang.NullPointerException ex) {
debug = “no”;
}
if(debug.equals(“yes”)) {
%>
<input type=”checkbox” id=”debug”
name=”output_debug_info” value=”yes” CHECKED></input>
<%
}
else {
%>
<input type=”checkbox” id=”debug”
name=”output_debug_info” value=”yes”></input>
<%


}
%>
</tr>
<tr>
<label for=”xalanVersion”>XSLT processor version:&nbsp;</label>
<%
String xalanVersion = “Xalan-Java 1”;
try {
xalanVersion = (String)
pageContext.getAttribute(“xalanVersion”, 4);
if(xalanVersion == null) {
xalanVersion = “Xalan-Java 1”;
}
}
catch(java.lang.NullPointerException ex) {
xalanVersion = “Xalan-Java 1”;
}
if(xalanVersion.equals(“Xalan-Java 1”)) {
%>
<input id=”xalan1” type=”radio” name=”xalanVersion”
value=”Xalan-Java 1” CHECKED>Xalan-Java 1&nbsp;</input>
<input id=”xalan2” type=”radio” name=”xalanVersion”
15 1089-9 XC 6/26/01 7:40 AM Page 682
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
683
C.65 Filename: TOMCAT_HOME\webapps\bonForum\jsp\forum\system_executes_command.jsp
value=”Xalan-Java 2”>Xalan-Java 2&nbsp;</input>
<%
}
else {

%>
<input id=”xalan1” type=”radio” name=”xalanVersion”
value=”Xalan-Java 1”>Xalan-Java 1&nbsp;</input>
<input id=”xalan2” type=”radio” name=”xalanVersion”
value=”Xalan-Java 2” CHECKED>Xalan-Java 2&nbsp;</input>
<%
}
%>
</tr>
<tr>
<input type=”hidden” name=”actorReturning”
value=”yes”></input>
<input type=”hidden” name=”bonCommand”
value=”system_executes_command”></input>
<input type=”submit” value=”set it!”
name=”submit”></input>
</tr>
</table>
</form>
</tr>
</table>
<font face=”Arial” color=”blue”>
<bon:outputDebugInfo type=”init”/>
</font>
<%— Examples of using a bean from JSP, discussed in chapter 8 of book
(you can put these outside of comment block to try them out):
—%>
<%—
<jsp:useBean id=”bonForumStore”
class=”de.tarent.forum.BonForumStore”

scope=”application”/>
<p>
hitTimeMillis: <jsp:getProperty name=”bonForumStore”
property=”hitTimeMillis”/> <BR>
initDate: <jsp:getProperty name=”bonForumStore”
property=”initDate”/> <BR>
reset hitTimeMillis! <jsp:setProperty name=”bonForumStore”
property=”hitTimeMillis” value=”HELLO!”/> <BR>
</p>
<p>
hitTimeMillis: <%=bonForumStore.getHitTimeMillis()%> <BR>
initDate: <%=bonForumStore.getInitDate()%> <BR>
</p>
<p>
reset hitTimeMillis! <% bonForumStore.setHitTimeMillis(“GOODBYE!”); %> <BR>
</p>
<% de.tarent.forum.BonForumStore bFS = (de.tarent.forum.BonForumStore)
15 1089-9 XC 6/26/01 7:40 AM Page 683
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
684
Appendix C Source Code for bonForum Web Application
pageContext.getAttribute(“bonForumStore”, 4);
%>
<p>
hitTimeMillis: <%= bFS.getHitTimeMillis()%> <BR>
initDate: <%= bFS.getInitDate()%> <BR>
</p>
<% bFS = (de.tarent.forum.BonForumStore)
pageContext.getServletContext().getAttribute(“bonForumStore”);
bFS.setHitTimeMillis(null);

%>
<p>
reset hitTimeMillis!<BR>
hitTimeMillis: <%= bFS.getHitTimeMillis()%> <BR>
initDate: <%= bFS.getInitDate()%> <BR>
</p>
<% bFS = (de.tarent.forum.BonForumStore)
application.getAttribute(“bonForumStore”);
%>
<p>
hitTimeMillis: <%= bFS.getHitTimeMillis()%> <BR>
initDate: <%= bFS.getInitDate()%> <BR>
</p>
—%>
</h5>
</font>
</body>
</html>
C.66 Filename: TOMCAT_HOME\webapps\
bonForum\jsp\forum\system_sets_timeout.jsp
<!doctype html public “-//w3c//dtd html 4.0 transitional//en”>
<%@ taglib uri=”
prefix=”bon” %>
<%@ page import=”java.io.*” %>
<%@ page errorPage=”forum_error.jsp” %>
<%—
This sets max inactivity timeout interval
for bonforum chat sessions
—%>
<html>

<head>
<meta http-equiv=”Content-Type”
content=”text/html;
charset=x-user-defined”>
</meta>
<title>
bonForum
</title>
15 1089-9 XC 6/26/01 7:40 AM Page 684
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
685
C.66 Filename: TOMCAT_HOME\webapps\bonForum\jsp\forum\system_sets_timeout.jsp
</head>
<body bgcolor=”#FFFF00”>
<table border=”0” rows=”2” width=”100%”>
<tr>
<td align=”left”>
<form name=”system_dumps_xml” method=”POST”
action=”/bonForum/servlet/BonForumEngine”>
<input type=”hidden” name=”actorReturning”
value=”no”></input>
<input type=”hidden” name=”bonCommand”
value=”system_executes_command”></input>
<p>
<input type=”submit” value=”Return” name=”submit”></input>
</p>
</form>
</td>
</tr>
<tr>

<td align=”left”>
<form method=”POST”
action=”/bonForum/servlet/BonForumEngine”>
<%
String sessionMaxInactiveMinutes = “”;
try {
sessionMaxInactiveMinutes = (String)
pageContext.getAttribute(“sessionMaxInactiveMinutes”, 4);
if(sessionMaxInactiveMinutes == null) {
sessionMaxInactiveMinutes = “-1”;
}
}
catch(java.lang.NullPointerException ex) {
sessionMaxInactiveMinutes = “-1”;
}
if(sessionMaxInactiveMinutes.equals(“”)) {
sessionMaxInactiveMinutes = “-1”;
pageContext.setAttribute(“sessionMaxInactiveMinutes”, “-1”, 4);
}
%>
<h4>
This JSP can be used to test and experiment with session lifetimes.
A setting of -1 means sessions do not timeout on the server.
If you set another value, the sessions will timeout if browser
inactivity exceeds that number of minutes.
When a session times out, the user
will be sent back to first page of webapp,
and their nickname will remain unavailable until bonForum restart.
Later, a user manager feature will be added to authenticate
users and restore their nicknames and other data.

Note that applet activity alone does not prevent session timeout.
</h4>
<p>Current Maximum Chat Inactivity in Minutes: <%=sessionMaxInactiveMinutes%></p>
15 1089-9 XC 6/26/01 7:40 AM Page 685
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
686
Appendix C Source Code for bonForum Web Application
<input type=”text” id=”timeout”
name=”sessionMaxInactiveMinutes” value=”<%=sessionMaxInactiveMinutes%>”
size=”5” maxlength=”9”></input>
<input type=”hidden” name=”actorReturning”
value=”yes”></input>
<input type=”hidden” name=”bonCommand”
value=”system_sets_timeout”></input>
<input type=”submit” value=”set”
name=”submit”></input>
</form>
</td>
</tr>
</table>
<font face=”Arial” color=”blue”>
<bon:outputDebugInfo/>
</font>
</body>
</html>
C.67 Filename: TOMCAT_HOME\webapps\
bonForum\jsp\forum\visitor_executes_choice.jsp
<!doctype html public “-//w3c//dtd html 4.0 transitional//en”>
<%@ taglib uri=”
prefix=”bon” %>

<%@ page errorPage=”forum_error.jsp” %>
<%—
here we force engine to check
for new subject and topic for new chat
—%>
<%
session.setAttribute(“newChatSubject”, “no”);
session.setAttribute(“newChatTopic”, “no”);
%>
<%—
here we can force actor to select
from available chats
—%>
<%—
session.setAttribute(“chatItem”, “NONE”);
—%>
<html>
<head>
<meta http-equiv=”Content-Type”
content=”text/html;
charset=x-user-defined”>
</meta>
<title>
bonForum
15 1089-9 XC 6/26/01 7:40 AM Page 686
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
687
C.67 Filename: TOMCAT_HOME\webapps\bonForum\jsp\forum\visitor_executes_choice.jsp
</title>
</head>

<body bgcolor=”#00FFFF”>
<font face=”Verdana”>
<a name=”entry”></a>
<h5>
<%— greet forum actor by nickname) —%>
<%
String actorNickname =
((String)session.getAttribute(“actorNickname”));
if(actorNickname == null ||
actorNickname.trim().length() < 1) {
actorNickname = “&lt;unknown visitor&gt;”;
}
String chatWelcomeMessage =
“Hello, “ + actorNickname +
“! Please make a choice:”;
%>
<table border=0 cellspacing=0 cellpadding=0 rows=5 cols=1
width=”100%” bgcolor=#00FFFF>
<tr>
<%= chatWelcomeMessage %>
</tr>
<form name=”visitor_executes_choice” method=”POST”
action=”/bonForum/servlet/BonForumEngine”>
<tr>
<label for=”join”>join a chat</label>
<input type=”radio” id=”join” name=”bonCommand”
value=”visitor_joins_chat”></input>
</tr>
<tr>
<label for=”start”>start a chat</label>

<input type=”radio” id=”start” name=”bonCommand”
value=”visitor_starts_chat” CHECKED></input>
</tr>
<tr>
<label for=”exit”>exit this forum</label>
<input type=”radio” id=”exit” name=”bonCommand”
value=”bonForum”></input>
</tr>
<tr>
<input type=”hidden” name=”actorReturning”
value=”yes”></input>
<input type=”submit” value=”do it!” name=”submit”></input>
</tr>
</form>
</table>
<font face=”Arial” color=”blue”>
<bon:outputDebugInfo/>
</font>
</h5>
15 1089-9 XC 6/26/01 7:40 AM Page 687
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
688
Appendix C Source Code for bonForum Web Application
</font>
<%@ include file=”../../mldocs/bonForumSplash.html” %>
</body>
</html>
C.68 Filename: TOMCAT_HOME\webapps\
bonForum\jsp\forum\visitor_joins_chat.jsp
<!doctype html public “-//w3c//dtd html 4.0 transitional//en”>

<%@ taglib uri=”
prefix=”bon” %>
<%@ page errorPage=”forum_error.jsp” %>
<%
session.setAttribute(“target”, “display”);
session.setAttribute(“document”,
request.getScheme() + “://” +
request.getServerName() + “:” +
request.getServerPort() +
“/bonForum/jsp/forum/visitor_joins_chat_frame.jsp”);
session.setAttribute(“refresh”, “true”);
session.setAttribute(“increment”, “30000”);
session.setAttribute(“limit”, “5000”);
session.setAttribute(“message”, “refreshing...”);
%>
<html>
<head>
<meta http-equiv=”Content-Type”
content=”text/html;
charset=x-user-defined”>
</meta>
<title>
bonForum
</title>
</head>
<noframes>/bonForum/noframe/html.index</noframes>
<frameset rows=”72%, 28%”>
<frame src=”/bonForum/jsp/forum/visitor_joins_chat_frame.jsp”
name=”display”/>
<frameset cols=”77%, 23%”>

<frame src=”/bonForum/jsp/forum/visitor_joins_chat_controls.jsp”
name=”controls”/>
<frame src=”/bonForum/jsp/forum/host_executes_chat_robot.jsp”
name=”robot”/>
<%— Note that all the bonForum states could share the same “refresh”
“_robot” JSP. For example, we tested the following one. But that
increases the interdependence of the frame contents in all states.
<frame src=”/bonForum/jsp/forum/actor_refreshes_frame_robot.jsp”
name=”robot”/>
—%>
15 1089-9 XC 6/26/01 7:40 AM Page 688
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
689
C.69 Filename: TOMCAT_HOME\webapps\bonForum\jsp\forum\visitor_joins_chat_controls.jsp
</frameset>
</frameset>
C.69 Filename: TOMCAT_HOME\webapps\
bonForum\jsp\forum\visitor_joins_chat_
controls.jsp
<!doctype html public “-//w3c//dtd html 4.0 transitional//en”>
<%@ taglib uri=”
prefix=”bon” %>
<%@ page errorPage=”forum_error.jsp” %>
<%— get actor nickname into a greeting: —%>
<%
String actorNickname =
((String)session.getAttribute(“actorNickname”));
if(actorNickname == null ||
actorNickname.trim().length() < 1) {
actorNickname = “&lt;unknown visitor&gt;”;

}
String chatJoinMessage =
“Join a chat, “ + actorNickname +
“! First choose one from the list.”;
%>
<html>
<head>
<meta http-equiv=”Content-Type”
content=”text/html;
charset=x-user-defined”>
</meta>
<title>
bonForum
</title>
</head>
<body bgcolor=”#00FFFF”>
<font face=”Verdana”>
<a name=”entry”></a>
<h5>
<%— a different frame lists the chats available —%>
<form method=”POST”
action=”/bonForum/servlet/BonForumEngine”>
<table border=0 cellspacing=0 cellpadding=0
rows=2 cols=1 width=100% bgcolor=#00FFFF>
<%— greet forum actor by nickname: —%>
<tr>
<%= chatJoinMessage %>
</tr>
<tr>
<input type=”hidden” name=”actorReturning”

15 1089-9 XC 6/26/01 7:40 AM Page 689
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
690
Appendix C Source Code for bonForum Web Application
value=”yes”></input>
<input type=”hidden” name=”bonCommand”
value=”visitor_joins_chat_ready”></input>
<input type=”submit” value=”join chat”
name=”submit”></input>
</tr>
</table>
</form>
<font face=”Arial” color=”blue”>
<bon:outputDebugInfo/>
</font>
</h5>
</font>
<%@ include file=”../../mldocs/bonForumBottom.html” %>
</body>
</html>
C.70 Filename: TOMCAT_HOME\webapps\
bonForum\jsp\forum\visitor_joins_chat_frame.
jsp
<!doctype html public “-//w3c//dtd html 4.0 transitional//en”>
<%@ taglib uri=”
prefix=”bon” %>
<%@ page import=”java.io.*” %>
<%@ page errorPage=”forum_error.jsp” %>
<%—
Here we get the currently chosen option.

After posting the form, the BonForumEngine servlet
forwards us back to this same page, updating
the display with the last selected chatItem.
—%>
<%
String chatItem = (String)session.getAttribute(“chatItem”);
String chatItemMessage = “chat: &lt;none&gt;”;
if(chatItem != null && chatItem.trim().length() > 0) {
String subject = “”;
String topic = “”;
subject = chatItem.substring(0, chatItem.indexOf(‘[‘) - 1);
subject = subject.replace(‘_’, ‘ ‘);
topic = chatItem.substring(chatItem.indexOf(‘[‘) + 1,
chatItem.lastIndexOf(‘]’));
chatItemMessage = “chat: “ + subject + “ —> “ + topic;
}
%>
<%—
Here later we can get a flag to select subset of available chats
and passed it to the XSLT via an XSL parameter
15 1089-9 XC 6/26/01 7:40 AM Page 690
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
691
C.70 Filename: TOMCAT_HOME\webapps\bonForum\jsp\forum\visitor_joins_chat_frame.jsp
Since chat selection based on flag is not yet implemented,
and XSLT needs one parameter, we pass an empty string for now.
—%>
<%
session.setAttribute(“param1”, “”);
%>

<html>
<head>
<meta http-equiv=”Content-Type”
content=”text/html;
charset=x-user-defined”>
</meta>
<title>
bonForum
</title>
</head>
<body bgcolor=”#00FFFF”>
<font face=”Verdana”>
<a name=”entry”></a>
<h5>
<form method=”POST”
action=”/bonForum/servlet/BonForumEngine”>
<table border=0 cellspacing=0 cellpadding=0
rows=3 cols=1 width=100% bgcolor=#00FFFF>
<%— Here we display the currently chosen chat —%>
<tr>
<%=chatItemMessage%>
</tr>
<%— here we list the available chats
in a select box created by the XSLT.
—%>
<tr>
<bon:transform type=”xalanVersion”
inXML=
“bonForumXML”
inXSL=

“..\\webapps\\bonForum\\mldocs\\bonChatItems.xsl”
outDoc=
“output”>
<%=output%>
</bon:transform>
</tr>
<%— LATER: chatModerated can filter the
list of available chats
<label for=”chatModerated”>Moderated chats only? </label>
<input type=”radio” name=”chatModerated”
value=”yes”>YES></input>
<input type=”radio” name=”chatModerated”
value=”no”>NO></input>
—%>
<tr>
15 1089-9 XC 6/26/01 7:40 AM Page 691
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
692
Appendix C Source Code for bonForum Web Application
<input type=”hidden” name=”actorReturning”
value=”yes”></input>
<input type=”hidden” name=”bonCommand”
value=”visitor_joins_chat_frame”></input>
<input type=”submit”
value=”choose the selected chat”
name=”submit”></input>
</tr>
</table>
</form>
<font face=”Arial” color=”blue”>

<bon:outputDebugInfo/>
</font>
</h5>
</font>
</body>
</html>
C.71 Filename: TOMCAT_HOME\webapps\
bonForum\jsp\forum\visitor_joins_chat_
ready.jsp
<!doctype html public “-//w3c//dtd html 4.0 transitional//en”>
<%@ taglib uri=”
prefix=”bon” %>
<%@ page errorPage=”forum_error.jsp” %>
<html>
<head>
<meta http-equiv=”Content-Type”
content=”text/html;
charset=x-user-defined”>
</meta>
<title>
bonForum
</title>
</head>
<body bgcolor=”#00FFFF”>
<%— go via robot to leave frameset —%>
<%—
Notice that this page uses request not session attributes
to send parameters to robot applet. It can do that since
the robot is acting as a “one-shot” and needs the attribute
data only one time. Also, all the pages that use the robot

to leave a frameset share the same robot.
—%>
<%—
here we prefix the scheme, host and port
of the web application server
15 1089-9 XC 6/26/01 7:40 AM Page 692
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
693
C.72 Filename: TOMCAT_HOME\webapps\bonForum\jsp\forum\visitor_joins_chat_robot.jsp
so the applet on the client can find it!
—%>
<%
request.setAttribute(“target”, “_top”);
request.setAttribute(“document”,
request.getScheme() + “://” +
request.getServerName() + “:” +
request.getServerPort() +
“/bonForum/jsp/forum/guest_executes_chat.jsp”);
request.setAttribute(“refresh”, “true”);
request.setAttribute(“increment”, “100”);
request.setAttribute(“limit”, “1”);
request.setAttribute(“message”, “Joining a chat!”);
%>
<%—These attributes become applet
parameters in robot page—%>
<jsp:forward page=”actor_leaves_frameset_robot.jsp.tfe”/>
</font>
</body>
</html>
C.72 Filename: TOMCAT_HOME\webapps\

bonForum\jsp\forum\visitor_joins_chat_
robot.jsp
<!doctype html public “-//w3c//dtd html 4.0 transitional//en”>
<%@ taglib uri=”
prefix=”bon” %>
<%@ page errorPage=”forum_error.jsp” %>
<%
String target = (String)session.getAttribute(“target”);
String document = (String)session.getAttribute(“document”);
String refresh = (String)session.getAttribute(“refresh”);
String increment = (String)session.getAttribute(“increment”);
String limit = (String)session.getAttribute(“limit”);
String message = (String)session.getAttribute(“message”);
%>
<%— message “debug” shows some info —%>
<html>
<head>
<meta http-equiv=”Content-Type”
content=”text/html;
charset=x-user-defined”>
</meta>
<title>
bonForum
15 1089-9 XC 6/26/01 7:40 AM Page 693
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
694
Appendix C Source Code for bonForum Web Application
</title>
</head>
<body bgcolor=”#00FFFF”>

<font face=”Verdana”>
<table>
<tr>
<img border=”0” src=”/bonForum/images/bonForumLogo.gif”
alt=”bonForum” width=”112” height=”112”>
</tr>
<tr>
<jsp:plugin type=”applet” code=”BonForumRobot.class”
codebase=”/bonForum/jsp/forum/applet”
jreversion=”1.3.0” width=”400” height=”160” >
<jsp:params>
<jsp:param name=”target” value=”<%=target%>”/>
<jsp:param name=”document” value=”<%=document%>”/>
<jsp:param name=”refresh” value=”<%=refresh%>”/>
<jsp:param name=”increment” value=”<%=increment%>”/>
<jsp:param name=”limit” value=”<%=limit%>”/>
<jsp:param name=”message” value=”<%=message%>”/>
</jsp:params>
<jsp:fallback>Plugin tag OBJECT or EMBED
not supported by browser.
</jsp:fallback>
</jsp:plugin>
</tr>
</table>
<font face=”Arial” color=”blue”>
<bon:outputDebugInfo/>
</font>
</font>
</body>
</html>

C.73 Filename: TOMCAT_HOME\webapps\
bonForum\jsp\forum\visitor_starts_chat.jsp
<!doctype html public “-//w3c//dtd html 4.0 transitional//en”>
<%@ taglib uri=”
prefix=”bon” %>
<%@ page errorPage=”forum_error.jsp” %>
<%— LATER: uncomment these six lines and
add a “robot” in a third frame below
to auto refresh chat subject list.
(See other examples elsewhere.)
<%
session.setAttribute(“target”, “display”);
session.setAttribute(“document”,
request.getScheme() + “://” +
15 1089-9 XC 6/26/01 7:40 AM Page 694
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
695
C.74 Filename: TOMCAT_HOME\webapps\bonForum\jsp\forum\visitor_starts_chat_controls.jsp
request.getServerName() + “:” +
request.getServerPort() +
“/bonForum/jsp/forum/visitor_starts_chat_frame.jsp”);
session.setAttribute(“refresh”, “true”);
session.setAttribute(“increment”, “5000”);
session.setAttribute(“limit”, “5000”);
session.setAttribute(“message”, “refreshing...”); %>
—%>
<html>
<head>
<meta http-equiv=”Content-Type”
content=”text/html;

charset=x-user-defined”>
</meta>
<title>
bonForum
</title>
</head>
<noframes>/bonForum/noframe/html.index</noframes>
<frameset rows=”65%, 35%”>
<frame src=”/bonForum/jsp/forum/visitor_starts_chat_frame.jsp.tfe”
name=”display”/>
<frame src=”/bonForum/jsp/forum/visitor_starts_chat_controls.jsp.tfe”
name=”controls”/>
</frameset>
</html>
C.74 Filename: TOMCAT_HOME\webapps\
bonForum\jsp\forum\visitor_starts_chat_
controls.jsp
<!doctype html public “-//w3c//dtd html 4.0 transitional//en”>
<%@ taglib uri=”
prefix=”bon” %>
<%@ page errorPage=”forum_error.jsp” %>
<%— get actor nickname into a greeting: —%>
<%
String actorNickname =
((String)session.getAttribute(“actorNickname”));
if(actorNickname == null ||
actorNickname.trim().length() < 1) {
actorNickname = “&lt;unknown visitor&gt;”;
}
String chatStartMessage =

“Start a chat, “ + actorNickname +
“! First select a subject category from the list.”;
%>
<%— get chat description, if any,
15 1089-9 XC 6/26/01 7:40 AM Page 695
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
696
Appendix C Source Code for bonForum Web Application
displayed by input form element —%>
<% String chatTopic =
(String)session.getAttribute(“chatTopic”);
if(chatTopic == null || chatTopic.trim().length() < 1) {
chatTopic = “”;
}
%>
<%
String chatSubjectAndTopic = “”;
try {
chatSubjectAndTopic =
(String)session.getAttribute(
“chatSubjectAndTopicTaken”);
if(!chatSubjectAndTopic.equals(“”)) {
chatSubjectAndTopic =
chatSubjectAndTopic + “ is taken! “ ;
}
if(chatSubjectAndTopic == null) {
chatSubjectAndTopic = “”;
}
}
catch(java.lang.NullPointerException ex) {

chatSubjectAndTopic = “”;
}
%>
<html>
<head>
<meta http-equiv=”Content-Type”
content=”text/html;
charset=x-user-defined”>
</meta>
<title>
bonForum
</title>
</head>
<body bgcolor=”#00FFFF”>
<font face=”Verdana”>
<a name=”entry”></a>
<h5>
<%— a different frame lists the subjects available—%>
<form method=”POST”
action=”/bonForum/servlet/BonForumEngine”>
<table border=0 cellspacing=0 cellpadding=0
rows=4 cols=1 width=50% bgcolor=#00FFFF>
<%— greet forum actor by nickname: —%>
<tr>
<%= chatStartMessage %>
<font color=”red”>
<%= chatSubjectAndTopic %>
</font>
</tr>
15 1089-9 XC 6/26/01 7:40 AM Page 696

Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
697
C.75 Filename: TOMCAT_HOME\webapps\bonForum\jsp\forum\visitor_starts_chat_frame.jsp
<tr>
<label for=”chatTopic”>
Then enter a description for your new chat:</label>
<input type=”text” value = “<%=chatTopic%>”
name=”chatTopic”></input>
</tr>
<tr>
<label for=”chatModerated”>Will you moderate this chat?
</label>
<input type=”radio” name=”chatModerated”
value=”yes”>YES</input>
<input type=”radio” name=”chatModerated”
value=”no” CHECKED>NO</input>
<input type=”hidden” name=”actorReturning”
value=”yes”></input>
<input type=”hidden” name=”bonCommand”
value=”visitor_starts_chat_ready”></input>
<input type=”submit” value=”start chat”
name=”submit”></input>
</tr>
</table>
</form>
<font face=”Arial” color=”blue”>
<bon:outputDebugInfo/>
</font>
</h5>
</font>

<%@ include file=”../../mldocs/bonForumBottom.html” %>
</body>
</html>
C.75 Filename: TOMCAT_HOME\webapps\
bonForum\jsp\forum\visitor_starts_chat_
frame.jsp
<!doctype html public “-//w3c//dtd html 4.0 transitional//en”>
<%@ taglib uri=”
prefix=”bon” %>
<%@ page errorPage=”forum_error.jsp” %>
<%— here we get the chat subject and
topic settings for later display —%>
<%
String chatSubject =
(String)session.getAttribute(“chatSubject”);
String chatSubjectMessage = “category: &lt;none&gt;”;
if(chatSubject != null && chatSubject.trim().length() > 0) {
chatSubjectMessage = “category: “ + chatSubject;
}
15 1089-9 XC 6/26/01 7:40 AM Page 697
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
698
Appendix C Source Code for bonForum Web Application
%>
<%
String chatTopic = (String)session.getAttribute(“chatTopic”);
String chatTopicMessage = “topic: &lt;none&gt;”;
if(chatTopic != null && chatTopic.trim().length() > 0) {
chatTopicMessage = “topic: “ + chatTopic;
}

%>
<html>
<head>
<meta http-equiv=”Content-Type”
content=”text/html;
charset=x-user-defined”>
</meta>
<title>
bonForum
</title>
</head>
<body bgcolor=”#00FFFF”>
<font face=”Verdana”>
<a name=”entry”></a>
<h5>
<%— here we list the chat categories available —%>
<form method=”POST”
action=”/bonForum/servlet/BonForumEngine”>
<table border=0 cellspacing=0 cellpadding=0
rows=4 cols=1 width=50% bgcolor=#00FFFF>
<tr>
<%=chatSubjectMessage%>
</tr>
<tr>
<%=chatTopicMessage%>
</tr>
<tr>
<select size=”12” name=”chatSubject”>
<bon:outputPathNames
docName=”bonForumXML”

pathToSubTreeRootNode=”bonForum.things.subjects”
ancestorReplacer=”COMPLETE_PATHS”
nodeSeparator=”/”>
<option><%= output %></option>
</bon:outputPathNames>
</select>
</tr>
<tr>
<input type=”hidden” name=”actorReturning”
value=”yes”></input>
<input type=”hidden” name=”bonCommand”
value=”visitor_starts_chat_frame”></input>
<input type=”submit” value=”choose selected chat subject”
name=”submit”></input>
15 1089-9 XC 6/26/01 7:40 AM Page 698
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
699
C.76 Filename: TOMCAT_HOME\webapps\bonForum\jsp\forum\visitor_starts_chat_ready.jsp
</tr>
</table>
</form>
<font face=”Arial” color=”blue”>
<bon:outputDebugInfo/>
</font>
</h5>
</font>
</body>
</html>
C.76 Filename: TOMCAT_HOME\webapps\
bonForum\jsp\forum\visitor_starts_chat_

ready.jsp
<!doctype html public “-//w3c//dtd html 4.0 transitional//en”>
<%@ taglib uri=”
prefix=”bon” %>
<%@ page errorPage=”forum_error.jsp” %>
<html>
<head>
<meta http-equiv=”Content-Type”
content=”text/html;
charset=x-user-defined”>
</meta>
<title>
bonForum
</title>
</head>
<body bgcolor=”#00FFFF”>
<%— go via robot to leave frameset —%>
<%—
Notice that this page uses request not session attributes
to send parameters to robot applet. It can do that since
the robot is acting as a “one-shot” and needs the attribute
data only one time. Also, all the pages that use the robot
to leave a frameset share the same robot.
—%>
<%—
here we prefix the scheme, host and port
of the web application server
so the applet on the client can find it!
—%>
<%

request.setAttribute(“target”, “_top”);
request.setAttribute(“document”,
request.getScheme() + “://” +
request.getServerName() + “:” +
15 1089-9 XC 6/26/01 7:40 AM Page 699
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
700
Appendix C Source Code for bonForum Web Application
request.getServerPort() +
“/bonForum/jsp/forum/host_executes_chat.jsp”);
request.setAttribute(“refresh”, “true”);
request.setAttribute(“increment”, “100”);
request.setAttribute(“limit”, “1”);
request.setAttribute(“message”, “Preparing new chat!”);
%>
<%—These attributes become applet
parameters in robot page—%>
<jsp:forward page=”actor_leaves_frameset_robot.jsp.tfe”/>
</font>
</body>
</html>
C.77 Filename: TOMCAT_HOME\webapps\
bonForum\jsp\forum\visitor_starts_chat_
robot.jsp
<!doctype html public “-//w3c//dtd html 4.0 transitional//en”>
<%@ taglib uri=”
prefix=”bon” %>
<%@ page errorPage=”forum_error.jsp” %>
<%
String target = (String)session.getAttribute(“target”);

String document = (String)session.getAttribute(“document”);
String refresh = (String)session.getAttribute(“refresh”);
String increment = (String)session.getAttribute(“increment”);
String limit = (String)session.getAttribute(“limit”);
String message = (String)session.getAttribute(“message”);
%>
<%— message “debug” shows some info —%>
<html>
<head>
<meta http-equiv=”Content-Type”
content=”text/html;
charset=x-user-defined”>
</meta>
<title>
bonForum
</title>
</head>
<body bgcolor=”#00FFFF”>
<font face=”Verdana”>
<table>
<tr>
<img border=”0” src=”/bonForum/images/bonForumLogo.gif”
alt=”bonForum” width=”112” height=”112”>
15 1089-9 XC 6/26/01 7:40 AM Page 700
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
701
C.77 Filename: TOMCAT_HOME\webapps\bonForum\jsp\forum\visitor_starts_chat_robot.jsp
</tr>
<tr>
<jsp:plugin type=”applet” code=”BonForumRobot.class”

codebase=”/bonForum/jsp/forum/applet”
jreversion=”1.3.0” width=”400” height=”160” >
<jsp:params>
<jsp:param name=”target” value=”<%=target%>”/>
<jsp:param name=”document” value=”<%=document%>”/>
<jsp:param name=”refresh” value=”<%=refresh%>”/>
<jsp:param name=”increment” value=”<%=increment%>”/>
<jsp:param name=”limit” value=”<%=limit%>”/>
<jsp:param name=”message” value=”<%=message%>”/>
</jsp:params>
<jsp:fallback>Plugin tag OBJECT or EMBED
not supported by browser.
</jsp:fallback>
</jsp:plugin>
</tr>
</table>
<font face=”Arial” color=”blue”>
<bon:outputDebugInfo/>
</font>
</font>
</body>
</html>
15 1089-9 XC 6/26/01 7:40 AM Page 701
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.

×