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

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

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

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=”http://www.bonForum.org/taglib/bonForum-taglib” 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=”http://www.bonForum.org/taglib/bonForum-taglib” 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=”http://www.bonForum.org/taglib/bonForum-taglib” 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=”http://www.bonForum.org/taglib/bonForum-taglib” 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=”http://www.bonForum.org/taglib/bonForum-taglib” 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. [...]... Java_ applets and applications 5.Trademarks and Logos.You acknowledge and agree as between you and Sun that Sun owns the SUN, SOLARIS, JAVA, JINI, FORTE, STAROFFICE, STARPORTAL and iPLANET trademarks and all SUN, SOLARIS, JAVA, JINI, FORTE, STAROFFICE, STARPORTAL and iPLANET-related trademarks, service marks, logos and other brand designations (“Sun Marks”), and you agree to comply with the Sun Trademark... distributed with Java applets and applications 5.Trademarks and Logos.You acknowledge and agree as between you and Sun that Sun owns the Java trademark and all Java-related trademarks, service marks, logos and other brand designations including the Coffee Cup logo and Duke logo (“Java Marks”), and you agree to comply with the Sun Trademark and Logo Usage Requirements currently located at http://www.sun.com/policies/trademarks... and Duke (“Java Marks”) and agrees to: (i) comply with the Java Trademark Guidelines at http://java.sun.com/trademarks.html; (ii) not do anything harmful to or inconsistent with Sun’s rights in the Java Marks; and (iii) assist Sun in protecting those rights, including assigning to Sun any rights acquired by Licensee in any Java Mark 4.TERM,TERMINATION AND SURVIVAL (A) The Agreement shall automatically... of any and all Programs and/ or Software 3 Java Technology Restrictions.You may not modify the Java Platform Interface (“JPI”, identified as classes contained within the “java” package or any subpackages of the “java” package), by creating additional classes within the JPI or otherwise causing the addition to or modification of the classes in the JPI In the event that you create an additional class and. .. the Java Runtime Environment binary code license (currently located at http://www.java.sun.com/jdk/index.html) for the availability of runtime code which may be distributed with Java applets and applications 5.Trademarks and Logos.You acknowledge and agree as between you and Sun that Sun owns the SUN, SOLARIS, JAVA, JINI, FORTE, STAROFFICE, STARPORTAL and iPLANET trademarks and all SUN, SOLARIS, JAVA,. .. Program (C) Java Platform Interface Licensee may not modify the Java Platform Interface (“JPI”, identified as classes contained within the “java” package or any subpackage of the “java” package), by creating additional classes within the JPI or otherwise causing the addition to or modification of the classes in the JPI In the event that Licensee creates any Java-related API and distributes such API... this watermark 16 1089-9 XD 6/26/01 7:42 AM Page 717 Sun Microsystems, Inc Binary Code License Agreement 717 (“JPI”, identified as classes contained within the “java” package or any subpackages of the “java” package), by creating additional classes within the JPI or otherwise causing the addition to or modification of the classes in the JPI In the event that you create an additional class and associated... than as provided with respect to Redistributables in Paragraph 2 above 4 Java Technology Restrictions.You may not modify the Java Platform Interface (“JPI”, identified as classes contained within the “java” package or any subpackages of the “java” package), by creating additional classes within the JPI or otherwise causing the addition to or modification of the classes in the JPI In the event that... value=””/> Plugin tag OBJECT or EMBED not supported by browser ... name=”document” value=””/> Plugin tag OBJECT or EMBED not supported by browser . null) { xalanVersion = “Xalan-Java 1”; } } catch(java.lang.NullPointerException ex) { xalanVersion = “Xalan-Java 1”; } if(xalanVersion.equals(“Xalan-Java 1”)). id=”xalan1” type=”radio” name=”xalanVersion” value=”Xalan-Java 1”>Xalan-Java 1&nbsp;</input> <input id=”xalan2” type=”radio” name=”xalanVersion”

Ngày đăng: 24/12/2013, 07:17

Từ khóa liên quan

Tài liệu cùng người dùng

Tài liệu liên quan