exam.jsp
exam.jsp
<html>
<head>
<meta http-equiv=Content-Type content="text/html; charset=GB2312">
<title>网上测试</title>
</head>
<body>
<%@ page language="java" contentType="text/html;charset=GB2312" buffer="none"%>
<jsp:useBean id="exam" scope="session" class="ch8.exam"/>
<FONT SIZE="+2"><B>
<%=exam.getExamName()%>
</B></FONT>
<br><br>
<%
int current=exam.getCurrent();
int iqn=0;
String questionNum=null;
questionNum=request.getParameter("QuestionNum");
if(questionNum==null) iqn=0;
else {
  Integer tmpInt=new Integer(questionNum);
  iqn=tmpInt.intValue();
}

if(iqn!=0)
{
  current++;
  exam.setCurrent(current);
}
  String answer=null;
  answer=request.getParameter("Answer");
if(answer==null)
{
  answer="";
}
if(exam.getCurrent()>exam.getCount())
{
  if(exam.getCorrect()>=6)
  {

%>
  <script language=javascript>
  self.location="pass.jsp?correct=<%out.print(exam.getCorrect()*10);%>"
  </script>
<%
  }
  else
  {
    exam.reset();
%>
  <script language=javascript>
  self.location="notpass.htm"
  </script>
<%
  }
}
else
{
  if(iqn==0)
  {
    if(answer. equals(exam.getCorrectAnswer(exam.getCurrent()-1)))
    {
      exam.setCorrect(exam.getCorrect()+1);
    }
  }
  else
  {
    if(answer.equals(exam.getCorrectAnswer(exam.getCurrent()-2)))
    {
      exam.setCorrect(exam.getCorrect()+1);
    }
  }
%>
  <FORM action="exam.jsp" method="post">
  <input type="hidden" name="QuestionNum" value="<%=current%>">
<P>
  总共<%=exam.getCount()%>个问题,现在是第<%=exam.getCurrent()%>个问题
</P>
<br>
<b>
  <%=current%>
</b>
<%=exam.getExamQuestion(current-1)%>
<br>
<input type="radio" name="Answer" value="A">
<%=exam.getExamAnswer(current-1,0)%>
<br>
<input type="radio" name="Answer" value="B">
<%=exam.getExamAnswer(current-1,1)%>
<br>
<input type="radio" name="Answer" value="C">
<%=exam.getExamAnswer(current-1,2)%>
<br>
<input type="radio" name="Answer" value="D">
<%=exam.getExamAnswer(current-1,3)%>
<br>
<input type="submit" value="确定">
</form>
<%}%>
</body>
</html>

exam.java
package ch8;
public class exam
{
    int count;
    int current;
    int correct;
    String examName;
//    String answer;
    String[] examQuestion=
    {
        "1.科学常识:下列有关科学家的叙述,何者正确?",
        "2.牛顿三大运动定律的第一定律是:",
        "3.两个报名参加海军的年轻人被问道:\"你们会游泳吗?\"他俩愣住了。过了一会儿,其中一个人回答说:\"怎么回事,难道船不够用吗?\"这篇文章的主题是什么",
        "4.接上题。考官为什么要问这两个人游泳的事?",
        "5.男:看那个妹妹,好靓哦!女:看你个大头鬼!问:这个女的是什么意思?",
        "6.男:今天天气不错。女:可不是咋得!问:这个女的什么意思?",
        "7.男:我把捡来的钱包交给警察了。男:我KAO!",
        "8.女:您好,您拨叫的用户没有开机,要留言请留言,不留言请挂机。问:这是发生在什么时候?",
        "9.ABCD四教授申请中科院院士,如果以下事实为真,谁最有资格入选",
        "10.以下是摘自电影《大话西游》中唐僧的一句台词,选项中可能正确的是人和妖精都是妈生的,不同的人是人他妈的,妖是妖他妈的,妖要有了仁慈之心,就不是妖了,而是人妖"
    };

    String[][] examAnswer=
    {
        {"(A)天文学家常常到天体营去研究天文的奥秘","(B)地质学家常常到地牢去研究地层结构","(C)大气科学家常常坐热气球到天空研究台风","(D)以上都不对"},
        {"(A)静如处子 动于脱兔","(B)静中有动 动中有静","(C)运动绝对 静止相对","(D)静者恒静 动者恒动"},
        {"(A)参军","(B)打鱼","(C)游泳","(D)造船"},
        {"(A)他想让他们教他游泳","(B)他想知道这两个人会不会被淹死","(C)他担心船不够用","(D)他想举行游泳比赛"},
        {"(A) 这个男的头有病","(B)这个男的头比较大","(C)这个男的看见的是鬼","(D)这个女的有点吃醋"},
        {"(A)今天天气不好","(B)今天天气很好","(C)这女的没听清","(D)这女的不知道"},
        {"(A)他很惊讶","(B)他丢了钱包","(C)他想揍第一个人","(D)他累了想找个地方靠靠"},
        {"(A)打电话","(B) 开飞机","(C) 发EMAIL","(D)坐飞机"},
        {"(A)是中国改革开放以後第一个公费留德的四十岁以下的女性的在微电子领域的花了少于三年毕业的毅然回国的博士","B是在使用黑白胶卷照出彩照这一国际前沿领域做出突破贡献的科学家","C毕业于我国著名的海南热带作物学院,学惯东西,差一点就复制出了恐龙。而且率先提出,中国人才没有断层,只是待遇和职称断层","D经常陪李岚清打敲三家和拱猪,对高校合并做出突出贡献"},
        {"(A)人妖是指:妈妈还健在就去做了和尚的妖精","(B)人和妖精没有本质区别,因为他们都是同一位女士生的","(C)唐僧为了超度一只妖精,不惜和妖精一起骂人","(D)唐僧暗示自己的母亲原来就是一只妖精变的"}
    };
    
    String[] correctAnswer=
    {
        "D","C","A","B","D","B","A","A","B","C"
    };

    String message;
    
    public exam()
    {
        reset();
    }

    public void reset()
    {
        count=10;
        current=1;
        correct=0;
        examName="中文GRE考试样题";
    }

    public void setCount(int c)
    {
        count=c;
    }

    public int getCount()
    {
        return count;
    }

    public void setCurrent(int c)
    {
        current=c;
    }

    public int getCurrent()
    {
        return current;
    }

    public void setCorrect(int c)
    {
        correct=c;
    }

    public int getCorrect()
    {
        return correct;
    }

    public void setExamName(String name)
    {
        examName=name;
    }

    public String getExamName()
    {
        return examName;
    }

    public void setCorrectAnswer(String[] answer)
    {
        correctAnswer=answer;
    }

    public void setCorrectAnswer(int i,String answer)
    {
        correctAnswer[i]=answer;
    }

    public String getCorrectAnswer(int i)
    {
        return correctAnswer[i];
    }

    public String[] getCorrectAnswer()
    {
        return correctAnswer;
    }

    public void setExamQuestion(String[] question)
    {
        examQuestion=question;
    }

    public void setExamQuestion(int i,String question)
    {
        examQuestion[i]=question;
    }

    public String[] getExamQuestion()
    {
        return examQuestion;
    }

    public String getExamQuestion(int i)
    {
        return examQuestion[i];
    }

    public void setExamAnswer(String[][] answer)
    {
        examAnswer=answer;
    }

    public void setExamAnswer(int i,String[] answer)
    {
        examAnswer[i]=answer;
    }

    public void setExamAnswer(int i ,int j,String answer)
    {
        examAnswer[i][j]=answer;
    }
    
    public String[][] getExamAnswer()
    {
        return examAnswer;
    }

    public String[] getExamAnswer(int i)
    {
        return examAnswer[i];
    }

    public String getExamAnswer(int i,int j)
    {
        return examAnswer[i][j];
    }
}


4.参考程序exam.jsp和exam.java
请修改exam.java里的代码:把第9题与第3题交换位置



shop.jsp
<%@page language="java" contentType="text/html;charset=GB2312"%>
<%@ page import="java.io.*"%>
<%@ page import="java.sql.*"%>
<%@ page import="java.util.*"%>
<html>
<head>
<META http-equiv=Content-Type content="text/html;charset=GB2312">
</head>
<body>
<jsp:useBean id="shop" scope="session" class="ch9_1.shopping"/>
<%
String sitem=null;
int item=0;
sitem=request.getParameter("Item");
if(sitem==null)
{
    sitem="";
}
else
{
    Integer tmpInt=new Integer(sitem);
    item=tmpInt.intValue();
}

String scount=null;
int count=0;
scount=request.getParameter("Count");
if(scount==null)
{
    scount="";
}
else
{
    Integer tmpInt=new Integer(scount);
    count=tmpInt.intValue();
}
String message=null;
%>
<center>
<table border="1" cellpadding="3" cellspacing="1">
<tr>
    <td>图像</td>
    <td>名称及介绍</td>
    <td>价格</td>
    <td>加入购物篮</td>
</tr>
<%
    for(int i=0;i<shop.getCount();i++)
    {
%>
<tr>
<td>
<img src="<%=shop.getItemImage(i)%>" height="120" width="120">
</td>
<td width="50%"><%=shop.getItemDesc(i)%></td>
    <td><%=shop.getItemPrice(i)%></td>
    <td>
    <a href="add.jsp?Item=<%=i%>&Count=1">
    加入购物篮
    </a>
    </td>
    </tr>
<%
    }
%>
</table>
</center>
</body>
</html>
5.参考程序shop.jsp
把灯泡的价格改为85,把打印机的价格改为650


感激不尽!!!