jsp在线考试系统-jsp文件

一个在线考试系统,测试你的jsp知识,代码不是特别多,所以不加注释了(http://jspbbs.yeah.net)

answer.jsp

1-- Include directive --
1@ include file="header.html" 
 1<table border="0" cellpadding="0" cellspacing="0">
 2<tr>
 3<td valign="TOP"><font face="Verdana, Arial, Helvetica, sans-serif">
 4<div align="RIGHT">
 5<font size="-1"><a href="/developer/Quizzes/index.html">Quizzes   
 6Index</a></font></div>
 7<h2 align="RIGHT"><font color="#FFFFFFF">JSP Professional, Chapter 12 Quiz   
 8Answers</font></h2>
 9<h4 align="RIGHT"><em>by Dan Malks</em></h4>
10<br/><br/>
11<table <tr="" border="0" cellpadding="2" cellspacing="8"><td>
12<font face="Verdana, Arial, Helvetica, sans-serif">   
13  

-- Page directive that applies to entire page. --

@ page language="java"

1  

-- Identifies bean as "worker" and tells the page where to locate the bean. --

1<jsp:usebean class="jdc.quiz.QuizResponses" id="worker" scope="request"></jsp:usebean>   
2  

-- Set bean properties with a wildcard. --

1<jsp:setproperty name="worker" property="*"></jsp:setproperty>   
2  
3  

-- Scoring --

1  

-- Variable declaration in code scriptlet --&gt;
&lt;% int score = 0;

1  
2<!-- Quiz Questions -->
3<!-- Question 1 -->
4<tr><td valign="TOP"><font face="Verdana, Arial, Helvetica, sans-serif">1.</font></td>   
5  

-- The method getOne() was set up in the bean with the id "worker" --

-- All Java code is enclosed in &lt;%

-- changed or updated. --

1  

if((worker.getOne() != null) &amp;&amp; ((worker.getOne()).equals("D"))) { score ++;

1  
2<td valign="TOP"><font face="Verdana, Arial, Helvetica, sans-serif"> <b>D</b>   
3is correct!</font></td>   
4  
5  

} else if (worker.getOne() != null) {

1  
2  
3<td valign="TOP"><font color="red"><jsp:getproperty name="worker" property="one"></jsp:getproperty>   
4is incorrect!</font></td>   
5  

} else {

1  
2<td valign="TOP">Blank <font color="red">X</font></td>   
3  

}

1  
2<td valign="TOP"><font face="Verdana, Arial, Helvetica, sans-serif">   
3Every JavaServer Pages<sup><font size="-2">TM</font></sup>   
4(JSP)<sup><font size="-2">TM</font></sup>source page is compiled into   
5a servlet before it is executed at runtime.<br/><br/></font></td></tr>
6<!-- Question 2 -->
7<tr><td valign="TOP"><font face="Verdana, Arial, Helvetica, sans-serif">2.</font></td>   
8  
9  

if ((worker.getTwo() != null) &amp;&amp; ((worker.getTwo()).equals("B"))) { score ++;

1  
2<td valign="TOP"><font face="Verdana, Arial, Helvetica, sans-serif"> <b>B</b>   
3is correct!<br/></font></td>   
4  
5  

} else if (worker.getTwo() != null) {

1  
2<td valign="TOP"><font face="Verdana, Arial, Helvetica, sans-serif">
3<font color="red"><jsp:getproperty name="worker" property="two"></jsp:getproperty> is   
4incorrect</font></font></td>   
5  

} else {

1<td valign="TOP"><font face="Verdana, Arial, Helvetica, sans-serif">   
2Blank   
3<font color="red">X</font></font></td>   
4  

}

 1  
 2<td valign="TOP"><font face="Verdana, Arial, Helvetica, sans-serif">   
 3When large amounts of Java scriptlet code are mixed with HTML markup   
 4within a JSP page, not only do readability and reuse suffer, but often   
 5bugs are introduced as web-production team members, who may not be   
 6familiar with Java programming, need to modify the accompanying markup.   
 7Additionally, dependencies now exist among various teams competing for the   
 8same file, making the development process less efficient.   
 9</font>
10</td></tr>
11<!-- Question 3 -->
12<tr><td valign="TOP"><font face="Verdana, Arial, Helvetica, sans-serif">3.</font></td>   
13  

if ((worker.getThree() != null) &amp;&amp; ((worker.getThree()).equals("D"))) { score ++;

1  
2<td valign="TOP"><font face="Verdana, Arial, Helvetica, sans-serif"> <b>D</b>   
3is correct!<br/></font></td>   
4  
5  

} else if (worker.getThree() != null) {

1  
2<td valign="TOP"><font face="Verdana, Arial, Helvetica, sans-serif">
3<font color="red"><jsp:getproperty name="worker" property="three"></jsp:getproperty> is   
4incorrect</font></font></td>   
5  

} else {

1<td valign="TOP"><font face="Verdana, Arial, Helvetica, sans-serif">   
2Blank <font color="red">X</font></font></td>   
3  

}

 1  
 2<td valign="TOP"><font face="Verdana, Arial, Helvetica, sans-serif">   
 3Doing an HTTP redirect requires a round-trip to the client. If this   
 4is not required, and the only desire is to forward the request to   
 5another resource, then this can be much more efficiently accomplished   
 6with the <code>RequestDispatcher</code>. Additionally, when using the   
 7dispatcher the state of the request object is maintained between   
 8resources, which will not be the case with the HTTP redirect.   
 9  
10</font></td></tr>
11<!-- Question 4 -->
12<tr><td valign="TOP"><font face="Verdana, Arial, Helvetica, sans-serif">4.</font></td>   
13  

if ((worker.getFour() != null) &amp;&amp; ((worker.getFour()).equals("C"))) { score ++;

1  
2<td valign="TOP"><font face="Verdana, Arial, Helvetica, sans-serif"> <b>C</b>   
3is correct!<br/></font></td>   
4  
5  

} else if (worker.getFour() != null) {

1  
2<td valign="TOP"><font face="Verdana, Arial, Helvetica, sans-serif">
3<font color="red"><jsp:getproperty name="worker" property="four"></jsp:getproperty> is   
4incorrect</font></font></td>   
5  

} else {

1  
2<td valign="TOP"><font face="Verdana, Arial, Helvetica, sans-serif">   
3Blank <font color="red">X</font></font></td>   
4  

}

 1  
 2<td valign="TOP"><font face="Verdana, Arial, Helvetica, sans-serif">   
 3Business logic is better contained in a   
 4JavaBean<sup><font size="-2">TM</font></sup> or a servlet, which is   
 5owned by a software developer. When lots of Java code is embedded   
 6directly within the JSP page as scriptlets, the   
 7"cut-and-paste" mentality tends to prevail when it comes   
 8to code reuse.   
 9</font>
10</td></tr>
11<!-- Question 5 -->
12<tr><td valign="TOP"><font face="Verdana, Arial, Helvetica, sans-serif">5.</font></td>   
13  

if ((worker.getFive() != null) &amp;&amp; ((worker.getFive()).equals("A"))) { score ++;

1  
2<td valign="TOP"> <font face="Verdana, Arial, Helvetica, sans-serif">
3<b>A</b> is correct!<br/></font></td>   
4  
5  

} else if (worker.getFive() != null) {

1  
2<td valign="TOP"><font face="Verdana, Arial, Helvetica, sans-serif">
3<font color="red"><jsp:getproperty name="worker" property="five"></jsp:getproperty> is   
4incorrect</font></font></td>   
5  

} else {

1<td valign="TOP"><font face="Verdana, Arial, Helvetica, sans-serif">   
2Blank <font color="red">X</font></font></td>   
3  

}

 1  
 2<td valign="TOP"><font face="Verdana, Arial, Helvetica, sans-serif">   
 3Since the servlet is the initial contact point for each request, it is   
 4well-suited to handle logic that is common across multiple requests.   
 5A good example of this type of logic is an authentication check.   
 6</font>
 7</td></tr>
 8<!-- Question 6 -->
 9<tr><td valign="TOP"><font face="Verdana, Arial, Helvetica, sans-serif">6.</font></td>   
10  

if ((worker.getSix() != null) &amp;&amp; ((worker.getSix()).equals("B"))) { score ++;

1  
2<td valign="TOP"> <font face="Verdana, Arial, Helvetica, sans-serif">
3<b>B</b> is correct!<br/></font></td>   
4  
5  

} else if (worker.getSix() != null) {

1  
2<td valign="TOP"><font face="Verdana, Arial, Helvetica, sans-serif">
3<font color="red"><jsp:getproperty name="worker" property="six"></jsp:getproperty> is   
4incorrect</font></font></td>   
5  

} else {

1  
2<td valign="TOP"><font face="Verdana, Arial, Helvetica, sans-serif">   
3Blank <font color="red">X</font></font></td>   
4  

}

 1  
 2<td valign="TOP"><font face="Verdana, Arial, Helvetica, sans-serif">   
 3Using a business delegate reduces coupling between the presentation   
 4and business tiers. The presentation tier has no knowledge of the   
 5EJB implementation details, such as Java Naming and Directory   
 6Interface<sup><font size="-2">TM</font></sup> lookup.   
 7</font>
 8</td></tr>
 9<!-- Question 7 -->
10<tr><td valign="TOP"><font face="Verdana, Arial, Helvetica, sans-serif">7.</font></td>   
11  

if ((worker.getSeven() != null) &amp;&amp; ((worker.getSeven()).equals("B"))) { score ++;

1  
2<td valign="TOP"><font face="Verdana, Arial, Helvetica, sans-serif">
3<b>B</b> is correct!<br/></font></td>   
4  
5  

} else if (worker.getSeven() != null) {

1  
2<td valign="TOP"><font face="Verdana, Arial, Helvetica, sans-serif">
3<font color="red"><jsp:getproperty name="worker" property="seven"></jsp:getproperty> is   
4incorrect</font></font></td>   
5  

} else {

1<td valign="TOP"><font face="Verdana, Arial, Helvetica, sans-serif">   
2Blank <font color="red">X</font></font></td>   
3  

}

 1  
 2<td valign="TOP"><font face="Verdana, Arial, Helvetica, sans-serif">   
 3Using Java scriptlets is the accepted method of doing iteration in   
 4JSP<sup><font size="-2">TM</font></sup> 1.0. In   
 5JSP<sup><font size="-2">TM</font></sup> 1.1, a custom tag may be used,   
 6which will hide the implementation details of the iteration code.   
 7  
 8</font></td></tr>
 9<!-- Question 8 -->
10<tr><td valign="TOP"><font face="Verdana, Arial, Helvetica, sans-serif">8\.   
11</font></td>   
12  

if ((worker.getEight() != null) &amp;&amp; ((worker.getEight()).equals("A"))) { score ++;

1  
2<td valign="TOP"><font face="Verdana, Arial, Helvetica, sans-serif">
3<b>A</b> is correct!<br/></font></td>   
4  
5  

} else if (worker.getEight() != null) {

1  
2<td valign="TOP"><font face="Verdana, Arial, Helvetica, sans-serif">
3<font color="red"><jsp:getproperty name="worker" property="eight"></jsp:getproperty> is   
4incorrect</font></font></td>   
5  

} else {

1<td><font face="Verdana, Arial, Helvetica, sans-serif">Blank   
2<font color="red">X</font></font></td>   
3  

}

 1  
 2<td valign="TOP"><font face="Verdana, Arial, Helvetica, sans-serif">   
 3The term <i>Page-Centric</i> is used to describe an architecture where   
 4the initial contact point for the request is a JSP page. An example   
 5is shown visually below:   
 6<p>
 7<img alt="JSP Page-Centric" height="204" src="Image1.gif" width="412"/>
 8</p></font>
 9</td></tr>
10<!-- Question 9 -->
11<tr><td valign="TOP"><font face="Verdana, Arial, Helvetica, sans-serif">9\.   
12</font></td>   
13  

if ((worker.getNine() != null) &amp;&amp; ((worker.getNine()).equals("A"))) { score ++;

1  
2<td valign="TOP"><font face="Verdana, Arial, Helvetica, sans-serif">
3<b>A</b> is correct!<br/></font></td>   
4  
5  

} else if (worker.getNine() != null) {

1  
2<td valign="TOP"><font face="Verdana, Arial, Helvetica, sans-serif">
3<font color="red"><jsp:getproperty name="worker" property="nine"></jsp:getproperty> is   
4incorrect</font></font></td>   
5  

} else {

1<td valign="TOP"><font face="Verdana, Arial, Helvetica, sans-serif">   
2Blank <font color="red">X</font></font></td>   
3  

}

 1  
 2<td valign="TOP"><font face="Verdana, Arial, Helvetica, sans-serif">   
 3When the forward method is used, the invoking resource does not regain   
 4control. Multiple include invocations can be made from the same   
 5resource, while the invoking resource maintains execution control.   
 6</font>
 7</td></tr>
 8<!-- Question 10 -->
 9<tr><td valign="TOP"><font face="Verdana, Arial, Helvetica, sans-serif">10\.   
10</font></td>   
11  

if ((worker.getTen() != null) &amp;&amp; ((worker.getTen()).equals("D"))) { score ++;

1  
2<td valign="TOP"> <b>D</b> is correct!<br/></td></tr></font></td>   
3  
4  

} else if (worker.getTen() != null) {

1  
2<td valign="TOP"><font face="Verdana, Arial, Helvetica, sans-serif">
3<font color="red"><jsp:getproperty name="worker" property="ten"></jsp:getproperty> is   
4incorrect</font></font></td>   
5  

} else {

1<td valign="TOP"><font face="Verdana, Arial, Helvetica, sans-serif">   
2Blank <font color="red">X</font></font></td>   
3  

}

 1  
 2<td valign="TOP"><font face="Verdana, Arial, Helvetica, sans-serif">   
 3Error pages are invoked when there is an uncaught exception from   
 4within a particular page. In this case, we mention that the   
 5<code>validationGaurd()</code> method might throw an exception.   
 6If this exception is not caught within the page, then we vector   
 7control to the <code>errorPage</code>, as stipulated in the attribute   
 8of the given page directive.   
 9  
10  
11</font></td></table></font></td></tr>   

-- Scoring calculations --

int missed = 10 - score;
double grade = (double)score/10*100;

 1  
 2<tr><td colspan="3"><font face="Verdana, Arial, Helvetica, sans-serif">
 3<p>You missed<strong> ```
 4= missed 
 5```</strong>
 6<br/>Your score is<strong> ```
 7= (int)grade 
 8``` </strong> percent.   
 9<h4>Source Code</h4>
10<p>This quiz used the <i>Page-View with Bean Approach</i>, detailed in <a href="/developer/Books/javaserverpages/">Chapter 12, JSP Archeticure</a>. The <a href="index.txt">first   
11page</a> of the quiz consists of regular HTML with a form that calls <a href="answer.txt"><code>answer.jsp</code></a>. <code>Answer.jsp</code> requests parameters from the bean,   
12in this case, called <a href="QuizResponses.txt">QuizResponses</a>. The <i>page-view with bean</i>   
13approach for this quiz required extra work to write the bean, and it could have been done using the   
14<i>page-view approach</i> without a bean, requesting invocation directly from the <code>answer.jsp</code>   
15page. Deciding which approach is preferrable depends on the application and how much HTML and Java   
16scriptlets need to be used. For this quiz we opted for the <i>page-view with bean</i> approach for   
17illustration purposes.   
18  
19<p><a href="/developer/Quizzes/jsp/index.html">Back to Quiz</a>
20<p><img align="LEFT" src="/images/T7.gif"/>
21</p></p></p></p></font></td></tr></table>
1<p>   
2  

@ include file="footer.html"

Published At
Categories with Web编程
Tagged with
comments powered by Disqus