posts - 44,  comments - 48,  trackbacks - 0

          ??????? 試題是模仿GRE考試,在這實(shí)例中,編了一套"中文GRE測(cè)試"總共有十道題,讀者可自行增加.
          ??????? 注:實(shí)例中的試題,可選答案,正確答案封裝在文件exam.java 中.用index.jsp文件來實(shí)現(xiàn)對(duì)問題的調(diào)用.核對(duì),顯示結(jié)果.所以要先編譯exam.java成exam.class ,之后index.jsp才能調(diào)用.

          少說費(fèi)話--直入主題:
          1.在Tomcat目錄下的webapps目錄下新建book文件夾,
          1.5 在Tomcat目錄下的conf/Catalina/localhost目錄下新建一個(gè)book.xml (這一步很重要!!)
          ?寫入:
          <?xml version='1.0' encoding='utf-8'?>
          <Context docBase="E:/Program Files/Apache Software Foundation/Tomcat 5.0/webapps/book" path="/book" reloadable="true">
          </Context>
          2.在book文件夾下新建WEB-INF文件夾.
          2.5 在WEB-INF目錄下新建web.xml 寫入:
          <?xml version="1.0" encoding="UTF-8"?>
          <web-app version="2.4"
          ?xmlns="
          http://java.sun.com/xml/ns/j2ee"
          ?xmlns:xsi="
          http://www.w3.org/2001/XMLSchema-instance"
          ?xsi:schemaLocation="
          http://java.sun.com/xml/ns/j2ee
          ?
          http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

          </web-app>
          3.在WEB-INF文件夾下新建classes文件夾.
          4.把index.jsp? exam.java 放到book目錄下.
          5.用javac? exam.java? 編譯exam.java成exam.jsp? (可在命令行中運(yùn)行此步)
          6.exam.jsp 放到WEB-INF/classes/exam目錄下.
          7.啟動(dòng)tomcat.
          8.輸入地址: http://localhost:8080/book???? 回車 OK !!!!
          Image00003.jpg


          附index.jsp代碼:
          <html>

          <head>
          <META http-equiv=Content-Type content="text/html; charset=GB2312">
          <title>網(wǎng)上測(cè)試</title>
          </head>

          <body>
          <%@ page language="java" contentType="text/html;charset=GB2312" buffer="none"%>
          <jsp:useBean id="exam" scope="session" class="exam.exam"/>
          <FONT SIZE="+2"><B>
          <%=exam.getExamName()%>
          </B></FONT>
          <br><br>
          <%
          int current=exam.getCurrent();
          String reset=null;
          reset=request.getParameter("Reset");
          if(reset==null){
          ?reset="";
          }
          if(reset.equals("1"))
          {
          ?exam.reset();
          }
          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)
          ?{
          %>
          ??恭喜!你以<%=exam.getCorrect()*10 %>分的成績(jī)通過了測(cè)試!<BR>
          <%
          ?}
          ?else
          ?{
          %>
          ??對(duì)不起,你需要60分以上的成績(jī)才能通過測(cè)試!<BR>
          ??你可以按<A HREF="exam.jsp?Reset=1">這里</A>重新進(jìn)行測(cè)試。<BR>
          <%
          ?}
          }
          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()%>個(gè)問題,現(xiàn)在是第<%=exam.getCurrent()%>個(gè)問題
          </P>
          <br>

          <b>
          ?<%=current%>
          </b>

          <%
          out.println(exam.getExamQuestion(current-1));
          %>
          <br>
          <input type="radio" name="Answer" value="A">
          <%
          out.println(exam.getExamAnswer(current-1,0));
          %>
          <br>

          <input type="radio" name="Answer" value="B">
          <%
          out.println(exam.getExamAnswer(current-1,1));
          %>
          <br>

          <input type="radio" name="Answer" value="C">
          <%
          out.println(exam.getExamAnswer(current-1,2));
          %>
          <br>

          <input type="radio" name="Answer" value="D">
          <%
          out.println(exam.getExamAnswer(current-1,3));
          %>
          <br>

          <input type="submit" value="確定">
          </form>
          <%
          }
          %>

          </body>

          </html>


          exam.java代碼:
          package exam;
          public class exam
          {
          ?int count;
          ?int current;
          ?int correct;
          ?String examName;
          //?String answer;
          ?String[] examQuestion=
          ?{//存放所有的問題
          ??"1.科學(xué)常識(shí):下列有關(guān)科學(xué)家的敘述,何者正確?",
          ??"2.牛頓三大運(yùn)動(dòng)定律的第一定律是:",
          ??"3.兩個(gè)報(bào)名參加海軍的年輕人被問道:\"你們會(huì)游泳嗎?\"他倆愣住了。過了一會(huì)兒,其中一個(gè)人回答說:\"怎么回事,難道船不夠用嗎?\"這篇文章的主題是什么",
          ??"4.接上題。考官為什么要問這兩個(gè)人游泳的事?",
          ??"5.男:看那個(gè)妹妹,好靚哦!女:看你個(gè)大頭鬼!問:這個(gè)女的是什么意思?",
          ??"6.男:今天天氣不錯(cuò)。女:可不是咋得!問:這個(gè)女的什么意思?",
          ??"7.男:我把撿來的錢包交給警察了。男:我KAO!",
          ??"8.女:您好,您撥叫的用戶沒有開機(jī),要留言請(qǐng)留言,不留言請(qǐng)掛機(jī)。問:這是發(fā)生在什么時(shí)候?",
          ??"9.ABCD四教授申請(qǐng)中科院院士,如果以下事實(shí)為真,誰最有資格入選",
          ??"10.以下是摘自電影《大話西游》中唐僧的一句臺(tái)詞,選項(xiàng)中可能正確的是人和妖精都是媽生的,不同的人是人他媽的,妖是妖他媽的,妖要有了仁慈之心,就不是妖了,而是人妖"
          ?};
          ?String[][] examAnswer=
          ?{//問題可選的答案
          ??{"(A)天文學(xué)家常常到天體營(yíng)去研究天文的奧秘","(B)地質(zhì)學(xué)家常常到地牢去研究地層結(jié)構(gòu)","(C)大氣科學(xué)家常常坐熱氣球到天空研究臺(tái)風(fēng)","(D)以上都不對(duì)"},
          ??{"(A)靜如處子 動(dòng)于脫兔","(B)靜中有動(dòng) 動(dòng)中有靜","(C)運(yùn)動(dòng)絕對(duì) 靜止相對(duì)","(D)靜者恒靜 動(dòng)者恒動(dòng)"},
          ??{"(A)參軍","(B)打魚","(C)游泳","(D)造船"},
          ??{"(A)他想讓他們教他游泳","(B)他想知道這兩個(gè)人會(huì)不會(huì)被淹死","(C)他擔(dān)心船不夠用","(D)他想舉行游泳比賽"},
          ??{"(A) 這個(gè)男的頭有病","(B)這個(gè)男的頭比較大","(C)這個(gè)男的看見的是鬼","(D)這個(gè)女的有點(diǎn)吃醋"},
          ??{"(A)今天天氣不好","(B)今天天氣很好","(C)這女的沒聽清","(D)這女的不知道"},
          ??{"(A)他很驚訝","(B)他丟了錢包","(C)他想揍第一個(gè)人","(D)他累了想找個(gè)地方靠靠"},
          ??{"(A)打電話","(B) 開飛機(jī)","(C) 發(fā)EMAIL","(D)坐飛機(jī)"},
          ??{"(A)是中國(guó)改革開放以后第一個(gè)公費(fèi)留德的四十歲以下的女性的在微電子領(lǐng)域的花了少于三年畢業(yè)的毅然回國(guó)的博士","(B)是在使用黑白膠卷照出彩照這一國(guó)際前沿領(lǐng)域做出突破貢獻(xiàn)的科學(xué)家","(C)畢業(yè)于我國(guó)著名的海南熱帶作物學(xué)院,學(xué)慣東西,差一點(diǎn)就復(fù)制出了恐龍。而且率先提出,中國(guó)人才沒有斷層,只是待遇和職稱斷層","(D)經(jīng)常陪李嵐清打敲三家和拱豬,對(duì)高校合并做出突出貢獻(xiàn)"},
          ??{"(A)人妖是指:媽媽還健在就去做了和尚的妖精","(B)人和妖精沒有本質(zhì)區(qū)別,因?yàn)樗麄兌际峭晃慌可?,"(C)唐僧為了超度一只妖精,不惜和妖精一起罵人","(D)唐僧暗示自己的母親原來就是一只妖精變的"}
          ?};
          ?
          ?String[] correctAnswer=
          ?{//正確的答案
          ??"D","C","A","B","D","B","A","A","B","C"
          ?};

          ?String message;
          ?
          ?public exam()
          ?{//重設(shè)測(cè)試
          ??reset();
          ?}

          ?public void reset()
          ?{//重設(shè)測(cè)試
          ??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];
          ?}
          }

          posted on 2006-09-06 10:57 摩西 閱讀(295) 評(píng)論(0)  編輯  收藏

          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 灵寿县| 阆中市| 金沙县| 姜堰市| 安阳市| 鄂尔多斯市| 嘉定区| 盐边县| 新晃| 鸡西市| 潜江市| 甘肃省| 黔南| 长岛县| 贵溪市| 西林县| 肇庆市| 英德市| 台山市| 黎川县| 桦甸市| 任丘市| 巴青县| 会昌县| 昌平区| 华宁县| 中江县| 社旗县| 霸州市| 临颍县| 柞水县| 泗阳县| 晋宁县| 伽师县| 松溪县| 新田县| 镇巴县| 泽库县| 丰原市| 二连浩特市| 林芝县|