⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 0173.htm

📁 精通struts源码,孙卫琴.经过更新后的,请查收,
💻 HTM
📖 第 1 页 / 共 2 页
字号:
&lt;TD&nbsp; VALIGN="TOP">&lt;FONT&nbsp; FACE="Verdana,&nbsp; Arial,&nbsp; Helvetica,&nbsp; sans-serif"><br>
Blank&nbsp; &lt;FONT&nbsp; COLOR=red>X&lt;/FONT>&lt;/FONT>&lt;/TD><br>
<br>
&lt;%&nbsp; }&nbsp; %><br>
<br>
&lt;TD&nbsp; VALIGN="TOP">&lt;FONT&nbsp; FACE="Verdana,&nbsp; Arial,&nbsp; Helvetica,&nbsp; sans-serif">&nbsp; <br>
Since&nbsp; the&nbsp; servlet&nbsp; is&nbsp; the&nbsp; initial&nbsp; contact&nbsp; point&nbsp; for&nbsp; each&nbsp; request,&nbsp; it&nbsp; is&nbsp; <br>
well-suited&nbsp; to&nbsp; handle&nbsp; logic&nbsp; that&nbsp; is&nbsp; common&nbsp; across&nbsp; multiple&nbsp; requests.&nbsp; <br>
A&nbsp; good&nbsp; example&nbsp; of&nbsp; this&nbsp; type&nbsp; of&nbsp; logic&nbsp; is&nbsp; an&nbsp; authentication&nbsp; check.&nbsp; <br>
&lt;/FONT>&nbsp; <br>
&lt;/TD>&lt;/TR><br>
<br>
&lt;!--&nbsp; Question&nbsp; 6&nbsp; --><br>
<br>
<br>
&lt;TR>&lt;TD&nbsp; VALIGN="TOP">&lt;FONT&nbsp; FACE="Verdana,&nbsp; Arial,&nbsp; Helvetica,&nbsp; sans-serif">6.&lt;/FONT>&lt;/TD><br>
<br>
&lt;%&nbsp; if&nbsp; ((worker.getSix()&nbsp; !=&nbsp; null)&nbsp; &&&nbsp; ((worker.getSix()).equals("B")))&nbsp; {&nbsp; score&nbsp; ++;&nbsp; %><br>
<br>
&lt;TD&nbsp; VALIGN="TOP">&nbsp; &lt;FONT&nbsp; FACE="Verdana,&nbsp; Arial,&nbsp; Helvetica,&nbsp; sans-serif"><br>
&lt;B>B&lt;/B>&nbsp; is&nbsp; correct!&lt;BR>&lt;/FONT>&lt;/TD><br>
<br>
<br>
&lt;%&nbsp; }&nbsp; else&nbsp; if&nbsp; (worker.getSix()&nbsp; !=&nbsp; null)&nbsp; {&nbsp; %><br>
<br>
&lt;TD&nbsp; VALIGN="TOP">&lt;FONT&nbsp; FACE="Verdana,&nbsp; Arial,&nbsp; Helvetica,&nbsp; sans-serif"><br>
&lt;FONT&nbsp; COLOR=red>&lt;jsp:getProperty&nbsp; name="worker"&nbsp; property="six"&nbsp; />&nbsp; is&nbsp; <br>
incorrect&lt;/FONT>&lt;/FONT>&lt;/TD><br>
<br>
&lt;%&nbsp; }&nbsp; else&nbsp; {&nbsp; %><br>
<br>
&lt;TD&nbsp; VALIGN="TOP">&lt;FONT&nbsp; FACE="Verdana,&nbsp; Arial,&nbsp; Helvetica,&nbsp; sans-serif"><br>
Blank&nbsp; &lt;FONT&nbsp; COLOR=red>X&lt;/FONT>&lt;/FONT>&lt;/TD><br>
<br>
&lt;%&nbsp; }&nbsp; %><br>
<br>
&lt;TD&nbsp; VALIGN="TOP">&lt;FONT&nbsp; FACE="Verdana,&nbsp; Arial,&nbsp; Helvetica,&nbsp; sans-serif">&nbsp; <br>
Using&nbsp; a&nbsp; business&nbsp; delegate&nbsp; reduces&nbsp; coupling&nbsp; between&nbsp; the&nbsp; presentation&nbsp; <br>
and&nbsp; business&nbsp; tiers.&nbsp; The&nbsp; presentation&nbsp; tier&nbsp; has&nbsp; no&nbsp; knowledge&nbsp; of&nbsp; the&nbsp; <br>
EJB&nbsp; implementation&nbsp; details,&nbsp; such&nbsp; as&nbsp; Java&nbsp; Naming&nbsp; and&nbsp; Directory&nbsp; <br>
Interface&lt;SUP>&lt;FONT&nbsp; SIZE="-2">TM&lt;/FONT>&lt;/SUP>&nbsp; lookup.<br>
&lt;/FONT>&nbsp; <br>
&lt;/TD>&lt;/TR><br>
<br>
&lt;!--&nbsp; Question&nbsp; 7&nbsp; --><br>
<br>
<br>
&lt;TR>&lt;TD&nbsp; VALIGN="TOP">&lt;FONT&nbsp; FACE="Verdana,&nbsp; Arial,&nbsp; Helvetica,&nbsp; sans-serif">7.&lt;/FONT>&lt;/TD><br>
<br>
&lt;%&nbsp; if&nbsp; ((worker.getSeven()&nbsp; !=&nbsp; null)&nbsp; &&&nbsp; ((worker.getSeven()).equals("B")))&nbsp; {&nbsp; score&nbsp; ++;&nbsp; %><br>
<br>
&lt;TD&nbsp; VALIGN="TOP">&lt;FONT&nbsp; FACE="Verdana,&nbsp; Arial,&nbsp; Helvetica,&nbsp; sans-serif">&nbsp; <br>
&lt;B>B&lt;/B>&nbsp; is&nbsp; correct!&lt;BR>&lt;/FONT>&lt;/TD><br>
<br>
<br>
&lt;%&nbsp; }&nbsp; else&nbsp; if&nbsp; (worker.getSeven()&nbsp; !=&nbsp; null)&nbsp; {&nbsp; %><br>
<br>
&lt;TD&nbsp; VALIGN="TOP">&lt;FONT&nbsp; FACE="Verdana,&nbsp; Arial,&nbsp; Helvetica,&nbsp; sans-serif"><br>
&lt;FONT&nbsp; COLOR=red>&lt;jsp:getProperty&nbsp; name="worker"&nbsp; property="seven"&nbsp; />&nbsp; is&nbsp; <br>
incorrect&lt;/FONT>&lt;/FONT>&lt;/TD><br>
<br>
&lt;%&nbsp; }&nbsp; else&nbsp; {&nbsp; %><br>
&lt;TD&nbsp; VALIGN="TOP">&lt;FONT&nbsp; FACE="Verdana,&nbsp; Arial,&nbsp; Helvetica,&nbsp; sans-serif"><br>
Blank&nbsp; &lt;FONT&nbsp; COLOR=red>X&lt;/FONT>&lt;/FONT>&lt;/TD><br>
<br>
&lt;%&nbsp; }&nbsp; %><br>
<br>
&lt;TD&nbsp; VALIGN="TOP">&lt;FONT&nbsp; FACE="Verdana,&nbsp; Arial,&nbsp; Helvetica,&nbsp; sans-serif">&nbsp; <br>
Using&nbsp; Java&nbsp; scriptlets&nbsp; is&nbsp; the&nbsp; accepted&nbsp; method&nbsp; of&nbsp; doing&nbsp; iteration&nbsp; in&nbsp; <br>
JSP&lt;SUP>&lt;FONT&nbsp; SIZE="-2">TM&lt;/FONT>&lt;/SUP>&nbsp; 1.0.&nbsp; In&nbsp; <br>
JSP&lt;SUP>&lt;FONT&nbsp; SIZE="-2">TM&lt;/FONT>&lt;/SUP>&nbsp; 1.1,&nbsp; a&nbsp; custom&nbsp; tag&nbsp; may&nbsp; be&nbsp; used,&nbsp; <br>
which&nbsp; will&nbsp; hide&nbsp; the&nbsp; implementation&nbsp; details&nbsp; of&nbsp; the&nbsp; iteration&nbsp; code.<br>
<br>
&lt;/FONT>&lt;/TD>&lt;/TR><br>
<br>
&lt;!--&nbsp; Question&nbsp; 8&nbsp; --><br>
<br>
<br>
&lt;TR>&lt;TD&nbsp; VALIGN="TOP">&lt;FONT&nbsp; FACE="Verdana,&nbsp; Arial,&nbsp; Helvetica,&nbsp; sans-serif">8.<br>
&lt;/FONT>&lt;/TD><br>
<br>
&lt;%&nbsp; if&nbsp; ((worker.getEight()&nbsp; !=&nbsp; null)&nbsp; &&&nbsp; ((worker.getEight()).equals("A")))&nbsp; {&nbsp; score&nbsp; ++;&nbsp; %><br>
<br>
&lt;TD&nbsp; VALIGN="TOP">&lt;FONT&nbsp; FACE="Verdana,&nbsp; Arial,&nbsp; Helvetica,&nbsp; sans-serif">&nbsp; <br>
&lt;B>A&lt;/B>&nbsp; is&nbsp; correct!&lt;BR>&lt;/FONT>&lt;/TD><br>
<br>
<br>
&lt;%&nbsp; }&nbsp; else&nbsp; if&nbsp; (worker.getEight()&nbsp; !=&nbsp; null)&nbsp; {&nbsp; %><br>
<br>
&lt;TD&nbsp; VALIGN="TOP">&lt;FONT&nbsp; FACE="Verdana,&nbsp; Arial,&nbsp; Helvetica,&nbsp; sans-serif"><br>
&lt;FONT&nbsp; COLOR=red>&lt;jsp:getProperty&nbsp; name="worker"&nbsp; property="eight"&nbsp; />&nbsp; is&nbsp; <br>
incorrect&lt;/FONT>&lt;/FONT>&lt;/TD><br>
<br>
&lt;%&nbsp; }&nbsp; else&nbsp; {&nbsp; %><br>
&lt;TD>&lt;FONT&nbsp; FACE="Verdana,&nbsp; Arial,&nbsp; Helvetica,&nbsp; sans-serif">Blank&nbsp; <br>
&lt;FONT&nbsp; COLOR=red>X&lt;/FONT>&lt;/FONT>&lt;/TD><br>
<br>
&lt;%&nbsp; }&nbsp; %><br>
<br>
&lt;TD&nbsp; VALIGN="TOP">&lt;FONT&nbsp; FACE="Verdana,&nbsp; Arial,&nbsp; Helvetica,&nbsp; sans-serif">&nbsp; <br>
The&nbsp; term&nbsp; &lt;I>Page-Centric&lt;/I>&nbsp; is&nbsp; used&nbsp; to&nbsp; describe&nbsp; an&nbsp; architecture&nbsp; where&nbsp; <br>
the&nbsp; initial&nbsp; contact&nbsp; point&nbsp; for&nbsp; the&nbsp; request&nbsp; is&nbsp; a&nbsp; JSP&nbsp; page.&nbsp; An&nbsp; example&nbsp; <br>
is&nbsp; shown&nbsp; visually&nbsp; below:<br>
&lt;P><br>
&lt;IMG&nbsp; SRC="Image1.gif"&nbsp; WIDTH="412"&nbsp; HEIGHT="204"&nbsp; ALT="JSP&nbsp; Page-Centric"><br>
&lt;/FONT>&nbsp; <br>
&lt;/TD>&lt;/TR><br>
<br>
&lt;!--&nbsp; Question&nbsp; 9&nbsp; --><br>
<br>
<br>
&lt;TR>&lt;TD&nbsp; VALIGN="TOP">&lt;FONT&nbsp; FACE="Verdana,&nbsp; Arial,&nbsp; Helvetica,&nbsp; sans-serif">9.<br>
&lt;/FONT>&lt;/TD><br>
<br>
&lt;%&nbsp; if&nbsp; ((worker.getNine()&nbsp; !=&nbsp; null)&nbsp; &&&nbsp; ((worker.getNine()).equals("A")))&nbsp; {&nbsp; score&nbsp; ++;&nbsp; %><br>
<br>
&lt;TD&nbsp; VALIGN="TOP">&lt;FONT&nbsp; FACE="Verdana,&nbsp; Arial,&nbsp; Helvetica,&nbsp; sans-serif">&nbsp; <br>
&lt;B>A&lt;/B>&nbsp; is&nbsp; correct!&lt;BR>&lt;/FONT>&lt;/TD><br>
<br>
<br>
&lt;%&nbsp; }&nbsp; else&nbsp; if&nbsp; (worker.getNine()&nbsp; !=&nbsp; null)&nbsp; {&nbsp; %><br>
<br>
&lt;TD&nbsp; VALIGN="TOP">&lt;FONT&nbsp; FACE="Verdana,&nbsp; Arial,&nbsp; Helvetica,&nbsp; sans-serif"><br>
&lt;FONT&nbsp; COLOR=red>&lt;jsp:getProperty&nbsp; name="worker"&nbsp; property="nine"&nbsp; />&nbsp; is&nbsp; <br>
incorrect&lt;/FONT>&lt;/FONT>&lt;/TD><br>
<br>
&lt;%&nbsp; }&nbsp; else&nbsp; {&nbsp; %><br>
&lt;TD&nbsp; VALIGN="TOP">&lt;FONT&nbsp; FACE="Verdana,&nbsp; Arial,&nbsp; Helvetica,&nbsp; sans-serif"><br>
Blank&nbsp; &lt;FONT&nbsp; COLOR=red>X&lt;/FONT>&lt;/FONT>&lt;/TD><br>
<br>
&lt;%&nbsp; }&nbsp; %><br>
<br>
&lt;TD&nbsp; VALIGN="TOP">&lt;FONT&nbsp; FACE="Verdana,&nbsp; Arial,&nbsp; Helvetica,&nbsp; sans-serif">&nbsp; <br>
When&nbsp; the&nbsp; forward&nbsp; method&nbsp; is&nbsp; used,&nbsp; the&nbsp; invoking&nbsp; resource&nbsp; does&nbsp; not&nbsp; regain&nbsp; <br>
control.&nbsp; Multiple&nbsp; include&nbsp; invocations&nbsp; can&nbsp; be&nbsp; made&nbsp; from&nbsp; the&nbsp; same&nbsp; <br>
resource,&nbsp; while&nbsp; the&nbsp; invoking&nbsp; resource&nbsp; maintains&nbsp; execution&nbsp; control.<br>
&lt;/FONT>&nbsp; <br>
&lt;/TD>&lt;/TR><br>
<br>
&lt;!--&nbsp; Question&nbsp; 10&nbsp; --><br>
<br>
<br>
&lt;TR>&lt;TD&nbsp; VALIGN="TOP">&lt;FONT&nbsp; FACE="Verdana,&nbsp; Arial,&nbsp; Helvetica,&nbsp; sans-serif">10.<br>
&lt;/FONT>&lt;/TD><br>
<br>
&lt;%&nbsp; if&nbsp; ((worker.getTen()&nbsp; !=&nbsp; null)&nbsp; &&&nbsp; ((worker.getTen()).equals("D")))&nbsp; {&nbsp; score&nbsp; ++;&nbsp; %><br>
<br>
&lt;TD&nbsp; VALIGN="TOP">&nbsp; &lt;B>D&lt;/B>&nbsp; is&nbsp; correct!&lt;BR>&lt;/FONT>&lt;/TD><br>
<br>
<br>
&lt;%&nbsp; }&nbsp; else&nbsp; if&nbsp; (worker.getTen()&nbsp; !=&nbsp; null)&nbsp; {&nbsp; %><br>
<br>
&lt;TD&nbsp; VALIGN="TOP">&lt;FONT&nbsp; FACE="Verdana,&nbsp; Arial,&nbsp; Helvetica,&nbsp; sans-serif"><br>
&lt;FONT&nbsp; COLOR=red>&lt;jsp:getProperty&nbsp; name="worker"&nbsp; property="ten"&nbsp; />&nbsp; is&nbsp; <br>
incorrect&lt;/FONT>&lt;/FONT>&lt;/TD><br>
<br>
&lt;%&nbsp; }&nbsp; else&nbsp; {&nbsp; %><br>
&lt;TD&nbsp; VALIGN="TOP">&lt;FONT&nbsp; FACE="Verdana,&nbsp; Arial,&nbsp; Helvetica,&nbsp; sans-serif"><br>
Blank&nbsp; &lt;FONT&nbsp; COLOR=red>X&lt;/FONT>&lt;/FONT>&lt;/TD><br>
<br>
&lt;%&nbsp; }&nbsp; %><br>
<br>
&lt;TD&nbsp; VALIGN="TOP">&lt;FONT&nbsp; FACE="Verdana,&nbsp; Arial,&nbsp; Helvetica,&nbsp; sans-serif"><br>
Error&nbsp; pages&nbsp; are&nbsp; invoked&nbsp; when&nbsp; there&nbsp; is&nbsp; an&nbsp; uncaught&nbsp; exception&nbsp; from&nbsp; <br>
within&nbsp; a&nbsp; particular&nbsp; page.&nbsp; In&nbsp; this&nbsp; case,&nbsp; we&nbsp; mention&nbsp; that&nbsp; the&nbsp; <br>
&lt;CODE>validationGaurd()&lt;/CODE>&nbsp; method&nbsp; might&nbsp; throw&nbsp; an&nbsp; exception.&nbsp; <br>
If&nbsp; this&nbsp; exception&nbsp; is&nbsp; not&nbsp; caught&nbsp; within&nbsp; the&nbsp; page,&nbsp; then&nbsp; we&nbsp; vector&nbsp; <br>
control&nbsp; to&nbsp; the&nbsp; &lt;CODE>errorPage&lt;/CODE>,&nbsp; as&nbsp; stipulated&nbsp; in&nbsp; the&nbsp; attribute&nbsp; <br>
of&nbsp; the&nbsp; given&nbsp; page&nbsp; directive.<br>
<br>
<br>
&lt;/FONT>&lt;/TD>&lt;/TR><br>
&lt;%--&nbsp; Scoring&nbsp; calculations&nbsp; --%><br>
&lt;%&nbsp; <br>
int&nbsp; missed&nbsp; =&nbsp; 10&nbsp; -&nbsp; score;<br>
double&nbsp; grade&nbsp; =&nbsp; (double)score/10*100;<br>
%><br>
<br>
&lt;TR>&lt;TD&nbsp; colspan="3">&lt;FONT&nbsp; FACE="Verdana,&nbsp; Arial,&nbsp; Helvetica,&nbsp; sans-serif">&nbsp; <br>
&lt;P>You&nbsp; missed&lt;STRONG>&nbsp; &lt;%=&nbsp; missed&nbsp; %>&lt;/STRONG><br>
&lt;BR>Your&nbsp; score&nbsp; is&lt;STRONG>&nbsp; &lt;%=&nbsp; (int)grade&nbsp; %>&nbsp; &lt;/STRONG>&nbsp; percent.<br>
&lt;H4>Source&nbsp; Code&lt;/H4><br>
&lt;P>This&nbsp; quiz&nbsp; used&nbsp; the&nbsp; &lt;I>Page-View&nbsp; with&nbsp; Bean&nbsp; Approach&lt;/I>,&nbsp; detailed&nbsp; in&nbsp; &lt;A&nbsp; <br>
HREF="/developer/Books/javaserverpages/">Chapter&nbsp; 12,&nbsp; JSP&nbsp; Archeticure&lt;/A>.&nbsp; The&nbsp; &lt;A&nbsp; HREF="index.txt">first&nbsp; <br>
page&lt;/A>&nbsp; of&nbsp; the&nbsp; quiz&nbsp; consists&nbsp; of&nbsp; regular&nbsp; HTML&nbsp; with&nbsp; a&nbsp; form&nbsp; that&nbsp; calls&nbsp; &lt;A&nbsp; <br>
HREF="answer.txt">&lt;CODE>answer.jsp&lt;/CODE>&lt;/A>.&nbsp; &lt;CODE>Answer.jsp&lt;/CODE>&nbsp; requests&nbsp; parameters&nbsp; from&nbsp; the&nbsp; bean,&nbsp; <br>
in&nbsp; this&nbsp; case,&nbsp; called&nbsp; &lt;A&nbsp; HREF="QuizResponses.txt">QuizResponses&lt;/A>.&nbsp; The&nbsp; &lt;I>page-view&nbsp; with&nbsp; bean&lt;/I>&nbsp; <br>
approach&nbsp; for&nbsp; this&nbsp; quiz&nbsp; required&nbsp; extra&nbsp; work&nbsp; to&nbsp; write&nbsp; the&nbsp; bean,&nbsp; and&nbsp; it&nbsp; could&nbsp; have&nbsp; been&nbsp; done&nbsp; using&nbsp; the&nbsp; <br>
&lt;I>page-view&nbsp; approach&lt;/I>&nbsp; without&nbsp; a&nbsp; bean,&nbsp; requesting&nbsp; invocation&nbsp; directly&nbsp; from&nbsp; the&nbsp; &lt;CODE>answer.jsp&lt;/CODE>&nbsp; <br>
page.&nbsp; Deciding&nbsp; which&nbsp; approach&nbsp; is&nbsp; preferrable&nbsp; depends&nbsp; on&nbsp; the&nbsp; application&nbsp; and&nbsp; how&nbsp; much&nbsp; HTML&nbsp; and&nbsp; Java&nbsp; <br>
scriptlets&nbsp; need&nbsp; to&nbsp; be&nbsp; used.&nbsp; For&nbsp; this&nbsp; quiz&nbsp; we&nbsp; opted&nbsp; for&nbsp; the&nbsp; &lt;I>page-view&nbsp; with&nbsp; bean&lt;/I>&nbsp; approach&nbsp; for&nbsp; <br>
illustration&nbsp; purposes.<br>
<br>
&lt;P>&lt;A&nbsp; HREF=/developer/Quizzes/jsp/index.html>Back&nbsp; to&nbsp; Quiz&lt;/A><br>
&lt;P>&lt;IMG&nbsp; SRC=/images/T7.gif&nbsp; ALIGN=LEFT><br>
<br>
<br>
&lt;/TABLE><br>
&lt;P>&nbsp; <br>
<br>
&lt;%@&nbsp; include&nbsp; file="footer.html"&nbsp; %>

  </table>
<p align="center"><script src="../../2.js"></script></a>
</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -