网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > JSP实例
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket
网络编程:ASP教程,ASP.NET教程,PHP教程,JSP教程,C#教程,数据库,XML教程,Ajax,Java,Perl,Shell,VB教程,Delphi,C/C++教程,软件工程,J2EE/J2ME,移动开发
本月文章推荐
. jsp计数器代码.
.轻松使用JSP生成饼图.
.如何使用JSP+MySQL创建留言本(二).
.jsp留言板源代码四: 给jsp初学者..
.JSP调用JavaBean在网页上动态生成.
.实例讲解JSP Model2体系结构(中.
.JBuilder2005实战JSP之错误处理(.
.jsp文件操作之读取篇.
.把一张图片变形扭曲成各种不同的.
.JSP与SQL SERVER的留言本.
.在jsp中用bean和servlet联合实现.
.JBuilder2005实战JSP之特殊页面(.
.如何使用JSP+MySQL创建留言本(一).
.jsp文件操作之追加篇.
.JSP单页面网站文件管理器.
.配置Web应用环境实现JSP留言簿.
.JSP抓取网页代码的程序.
.用JSP/ASP创建WAP应用.
.jsp实现购物程序.
.jsp计数器-jsp文件.

jsp在线考试系统-jsp文件

发表日期:2000-12-11


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

answer.jsp

<%-- Include directive --%>
<%@ include file="header.html" %>

<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0">
<TR>
<TD VALIGN="TOP"><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
<DIV ALIGN="RIGHT">
<FONT SIZE="-1"><A HREF="/developer/Quizzes/index.html">Quizzes
Index</A></FONT></DIV>
<H2 ALIGN="RIGHT"><FONT COLOR="#FFFFFFF">JSP Professional, Chapter 12 Quiz
Answers</FONT></H2>
<H4 ALIGN="RIGHT"><EM>by Dan Malks</EM></H4>
<BR><BR>
<TABLE BORDER="0" CELLSPACING="8" CELLPADDING="2" <TR><TD>
<FONT FACE="Verdana, Arial, Helvetica, sans-serif">

<%-- Page directive that applies to entire page. --%>
<%@ page language="java" %>

<%-- Identifies bean as "worker" and tells the page where to locate the bean. --%>
<jsp:useBean id="worker" class="jdc.quiz.QuizResponses" scope="request" />

<%-- Set bean properties with a wildcard. --%>
<jsp:setProperty name="worker" property="*" />


<%-- Scoring --%>

<%-- Variable declaration in code scriptlet -->
<% int score = 0; %>

<!-- Quiz Questions -->

<!-- Question 1 -->

<TR><TD VALIGN="TOP"><FONT FACE="Verdana, Arial, Helvetica, sans-serif">1.</FONT></TD>

<%-- The method getOne() was set up in the bean with the id "worker" --%>
<%-- All Java code is enclosed in <% %>, leaving HTML to be easily --%>
<%-- changed or updated. --%>

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

<TD VALIGN="TOP"><FONT FACE="Verdana, Arial, Helvetica, sans-serif"> <B>D</B>
is correct!</FONT></TD>


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


<TD VALIGN="TOP"><FONT COLOR=red><jsp:getProperty name="worker" property="one" />
is incorrect!</FONT></TD>

<% } else { %>

<TD VALIGN="TOP">Blank <FONT COLOR=red>X</FONT></TD>

<% } %>

<TD VALIGN="TOP"><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
Every JavaServer Pages<SUP><FONT SIZE="-2">TM</FONT></SUP>
(JSP)<SUP><FONT SIZE="-2">TM</FONT></SUP>source page is compiled into
a servlet before it is executed at runtime.</A><BR><BR></FONT></TD></TR>

<!-- Question 2 -->


<TR><TD VALIGN="TOP"><FONT FACE="Verdana, Arial, Helvetica, sans-serif">2.</FONT></TD>


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

<TD VALIGN="TOP"><FONT FACE="Verdana, Arial, Helvetica, sans-serif"> <B>B</B>
is correct!<BR></FONT></TD>


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

<TD VALIGN="TOP"><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
<FONT COLOR=red><jsp:getProperty name="worker" property="two" /> is
incorrect</FONT></TD>

<% } else { %>
<TD VALIGN="TOP"><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
Blank
<FONT COLOR=red>X</FONT></FONT></TD>

<% } %>

<TD VALIGN="TOP"><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
When large amounts of Java scriptlet code are mixed with HTML markup
within a JSP page, not only do readability and reuse suffer, but often
bugs are introduced as web-production team members, who may not be
familiar with Java programming, need to modify the accompanying markup.
Additionally, dependencies now exist among various teams competing for the
same file, making the development process less efficient.
</FONT>
</TD></TR>

<!-- Question 3 -->


<TR><TD VALIGN="TOP"><FONT FACE="Verdana, Arial, Helvetica, sans-serif">3.</FONT></TD>

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

<TD VALIGN="TOP"><FONT FACE="Verdana, Arial, Helvetica, sans-serif"> <B>D</B>
is correct!<BR></FONT></TD>


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

<TD VALIGN="TOP"><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
<FONT COLOR=red><jsp:getProperty name="worker" property="three" /> is
incorrect</FONT></FONT></TD>

<% } else { %>
<TD VALIGN="TOP"><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
Blank <FONT COLOR=red>X</FONT></FONT></TD>

<% } %>

<TD VALIGN="TOP"><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
Doing an HTTP redirect requires a round-trip to the client. If this
is not required, and the only desire is to forward the request to
another resource, then this can be much more efficiently accomplished
with the <CODE>RequestDispatcher</CODE>. Additionally, when using the
dispatcher the state of the request object is maintained between
resources, which will not be the case with the HTTP redirect.

</FONT></TD></TR>

<!-- Question 4 -->


<TR><TD VALIGN="TOP"><FONT FACE="Verdana, Arial, Helvetica, sans-serif">4.</TD>

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

<TD VALIGN="TOP"><FONT FACE="Verdana, Arial, Helvetica, sans-serif"> <B>C</B>
is correct!<BR></FONT></TD>


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

<TD VALIGN="TOP"><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
<FONT COLOR=red><jsp:getProperty name="worker" property="four" /> is
incorrect</FONT></FONT></TD>

<% } else { %>

<TD VALIGN="TOP"><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
Blank <FONT COLOR=red>X</FONT></FONT></TD>

<% } %>

<TD VALIGN="TOP"><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
Business logic is better contained in a
JavaBean<SUP><FONT SIZE="-2">TM</FONT></SUP> or a servlet, which is
owned by a software developer. When lots of Java code is embedded
directly within the JSP page as scriptlets, the
&quot;cut-and-paste&quot; mentality tends to prevail when it comes
to code reuse.
</FONT>
</TD></TR>

<!-- Question 5 -->


<TR><TD VALIGN="TOP"><FONT FACE="Verdana, Arial, Helvetica, sans-serif">5.</FONT></TD>

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

<TD VALIGN="TOP"> <FONT FACE="Verdana, Arial, Helvetica, sans-serif">
<B>A</B> is correct!<BR></FONT></TD>


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

<TD VALIGN="TOP"><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
<FONT COLOR=red><jsp:getProperty name="worker" property="five" /> is
incorrect</FONT></FONT></TD>

<% } else { %>
<TD VALIGN="TOP"><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
Blank <FONT COLOR=red>X</FONT></FONT></TD>

<% } %>

<TD VALIGN="TOP"><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
Since the servlet is the initial contact point for each request, it is
well-suited to handle logic that is common across multiple requests.
A good example of this type of logic is an authentication check.
</FONT>
</TD></TR>

<!-- Question 6 -->


<TR><TD VALIGN="TOP"><FONT FACE="Verdana, Arial, Helvetica, sans-serif">6.</FONT></TD>

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

<TD VALIGN="TOP"> <FONT FACE="Verdana, Arial, Helvetica, sans-serif">
<B>B</B> is correct!<BR></FONT></TD>


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

<TD VALIGN="TOP"><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
<FONT COLOR=red><jsp:getProperty name="worker" property="six" /> is
incorrect</FONT></FONT></TD>

<% } else { %>

<TD VALIGN="TOP"><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
Blank <FONT COLOR=red>X</FONT></FONT></TD>

<% } %>

<TD VALIGN="TOP"><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
Using a business delegate reduces coupling between the presentation
and business tiers. The presentation tier has no knowledge of the
EJB implementation details, such as Java Naming and Directory
Interface<SUP><FONT SIZE="-2">TM</FONT></SUP> lookup.
</FONT>
</TD></TR>

<!-- Question 7 -->


<TR><TD VALIGN="TOP"><FONT FACE="Verdana, Arial, Helvetica, sans-serif">7.</FONT></TD>

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

<TD VALIGN="TOP"><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
<B>B</B> is correct!<BR></FONT></TD>


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

<TD VALIGN="TOP"><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
<FONT COLOR=red><jsp:getProperty name="worker" property="seven" /> is
incorrect</FONT></FONT></TD>

<% } else { %>
<TD VALIGN="TOP"><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
Blank <FONT COLOR=red>X</FONT></FONT></TD>

<% } %>

<TD VALIGN="TOP"><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
Using Java scriptlets is the accepted method of doing iteration in
JSP<SUP><FONT SIZE="-2">TM</FONT></SUP> 1.0. In
JSP<SUP><FONT SIZE="-2">TM</FONT></SUP> 1.1, a custom tag may be used,
which will hide the implementation details of the iteration code.

</FONT></TD></TR>

<!-- Question 8 -->


<TR><TD VALIGN="TOP"><FONT FACE="Verdana, Arial, Helvetica, sans-serif">8.
</FONT></TD>

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

<TD VALIGN="TOP"><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
<B>A</B> is correct!<BR></FONT></TD>


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

<TD VALIGN="TOP"><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
<FONT COLOR=red><jsp:getProperty name="worker" property="eight" /> is
incorrect</FONT></FONT></TD>

<% } else { %>
<TD><FONT FACE="Verdana, Arial, Helvetica, sans-serif">Blank
<FONT COLOR=red>X</FONT></FONT></TD>

<% } %>

<TD VALIGN="TOP"><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
The term <I>Page-Centric</I> is used to describe an architecture where
the initial contact point for the request is a JSP page. An example
is shown visually below:
<P>
<IMG SRC="Image1.gif" WIDTH="412" HEIGHT="204" ALT="JSP Page-Centric">
</FONT>
</TD></TR>

<!-- Question 9 -->


<TR><TD VALIGN="TOP"><FONT FACE="Verdana, Arial, Helvetica, sans-serif">9.
</FONT></TD>

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

<TD VALIGN="TOP"><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
<B>A</B> is correct!<BR></FONT></TD>


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

<TD VALIGN="TOP"><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
<FONT COLOR=red><jsp:getProperty name="worker" property="nine" /> is
incorrect</FONT></FONT></TD>

<% } else { %>
<TD VALIGN="TOP"><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
Blank <FONT COLOR=red>X</FONT></FONT></TD>

<% } %>

<TD VALIGN="TOP"><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
When the forward method is used, the invoking resource does not regain
control. Multiple include invocations can be made from the same
resource, while the invoking resource maintains execution control.
</FONT>
</TD></TR>

<!-- Question 10 -->


<TR><TD VALIGN="TOP"><FONT FACE="Verdana, Arial, Helvetica, sans-serif">10.
</FONT></TD>

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

<TD VALIGN="TOP"> <B>D</B> is correct!<BR></FONT></TD>


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

<TD VALIGN="TOP"><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
<FONT COLOR=red><jsp:getProperty name="worker" property="ten" /> is
incorrect</FONT></FONT></TD>

<% } else { %>
<TD VALIGN="TOP"><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
Blank <FONT COLOR=red>X</FONT></FONT></TD>

<% } %>

<TD VALIGN="TOP"><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
Error pages are invoked when there is an uncaught exception from
within a particular page. In this case, we mention that the
<CODE>validationGaurd()</CODE> method might throw an exception.
If this exception is not caught within the page, then we vector
control to the <CODE>errorPage</CODE>, as stipulated in the attribute
of the given page directive.


</FONT></TD></TR>
<%-- Scoring calculations --%>
<%
int missed = 10 - score;
double grade = (double)score/10*100;
%>

<TR><TD colspan="3"><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
<P>You missed<STRONG> <%= missed %></STRONG>
<BR>Your score is<STRONG> <%= (int)grade %> </STRONG> percent.
<H4>Source Code</H4>
<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
page</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,
in this case, called <A HREF="QuizResponses.txt">QuizResponses</A>. The <I>page-view with bean</I>
approach for this quiz required extra work to write the bean, and it could have been done using the
<I>page-view approach</I> without a bean, requesting invocation directly from the <CODE>answer.jsp</CODE>
page. Deciding which approach is preferrable depends on the application and how much HTML and Java
scriptlets need to be used. For this quiz we opted for the <I>page-view with bean</I> approach for
illustration purposes.

<P><A HREF=/developer/Quizzes/jsp/index.html>Back to Quiz</A>
<P><IMG SRC=/images/T7.gif ALIGN=LEFT>


</TABLE>
<P>

<%@ include file="footer.html" %>
上一篇:jsp在线考试系统-htm文件 人气:17068
下一篇:jsp在线考试系统-bean文件 人气:16509
浏览全部的内容 Dreamweaver插件下载 网页广告代码 祝你圣诞节快乐 2009年新年快乐