欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

使用JSP技術(shù)實(shí)現(xiàn)一個(gè)簡(jiǎn)單的在線測(cè)試系統(tǒng)的實(shí)例詳解

 更新時(shí)間:2020年08月05日 17:30:17   作者:01020906  
這篇文章主要介紹了使用JSP技術(shù)實(shí)現(xiàn)一個(gè)簡(jiǎn)單的在線測(cè)試系統(tǒng)的實(shí)例詳解,文章通過(guò)示例代碼和代碼運(yùn)行結(jié)果圖相結(jié)合展示介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧

1、登陸界面

實(shí)現(xiàn):

本界面由三部分構(gòu)成,F(xiàn)ooter.jsp,Index.jsp,Header.jsp

Header.jsp

<center>
	<h2>在線測(cè)試系統(tǒng)</h2>
	<p>
		<a href="Index.jsp" rel="external nofollow" >登錄</a>
		|
		<a href="test.jsp" rel="external nofollow" >在線測(cè)試</a>
		|
		<a href="scorelist.jsp" rel="external nofollow" >成績(jī)榜</a>
	</p>
</center>

該部分主要實(shí)現(xiàn)主界面的頭部信息,顯示三個(gè)鏈接,分別可以跳轉(zhuǎn)到登陸界面,在線測(cè)試界面,以及成績(jī)榜界面

 Footer.jsp

<%!int pageCount = 0;%>
<% pageCount++; %>
<center>
 <p>Copyright @ 2018 | 訪問(wèn)次數(shù):<%=pageCount%></p>
</center>

該部分顯示登錄頁(yè)面的底部信息,即顯示訪問(wèn)次數(shù)等其他信息

 Index.jsp

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<jsp:include page="Header.jsp" />
<center>
<form action="check.jsp" method="get">
用戶名<input type="text" name="username" />
<br>
密碼<input type="password" name="psd" />
<br><br>
<button type="submit">登錄</button>
<button type="reset">重填</button>
</center>
<jsp:include page="Footer.jsp" />
</form>
</body>
</html>

該部分主要顯示登陸界面的中間界面,用戶可以輸入用戶名和密碼實(shí)現(xiàn)登陸系統(tǒng)

 2、登陸檢測(cè)

當(dāng)用戶點(diǎn)擊登陸按鈕,系統(tǒng)后臺(tái)會(huì)獲取用戶輸入的用戶名以及密碼,并與預(yù)設(shè)的進(jìn)行比對(duì),由于本例沒(méi)有使用數(shù)據(jù)庫(kù),所以使用Map存儲(chǔ)用戶名及密碼

<%!
Map<String,String> userlist= new HashMap<String,String>();
%>
 
<%
userlist.put("qq", "11");
userlist.put("ww","22");
userlist.put("ee","33");
%>
 
<%!
boolean check(String username,String psd){
	if(userlist.containsKey(username)){
		if(userlist.get(username).equals(psd)){
			return true;
		}
	}
	
	return false;
}
 
%>
 
 
<%
String username=request.getParameter("username");
String psd=request.getParameter("psd");
if(check(username,psd)){
	session.setAttribute("username", username);
	
	out.print("歡迎"+username);
	out.print("<a href='test.jsp'>開始測(cè)試</a>");
}
else{
	out.print("登陸失敗,3秒鐘后重新登錄");
	response.setHeader("refresh", "3;url='Index.jsp'");
}
 
%>

當(dāng)用戶輸入的用戶名及密碼正確時(shí),系統(tǒng)會(huì)顯示用戶姓名,以及跳轉(zhuǎn)鏈接,同時(shí)使用session保存用戶名,密碼不正確時(shí),3秒后返回登陸界面,

 3、測(cè)試頁(yè)面

用戶輸入用戶名及密碼后便進(jìn)入測(cè)試頁(yè)面,測(cè)試頁(yè)面的第一行顯示用戶名,之后顯示題目信息。

<%
String username=(String)session.getAttribute("username"); 
if(username==null){
	out.print("未登陸,3秒鐘后重新登錄");
	response.setHeader("refresh", "3;url='Index.jsp'");
}
else{
	%>
	
	考生:<%=session.getAttribute("username") %>
 
<h3>在線測(cè)試題</h3>
<form action="submit.jsp" onsubmit="return confirm('確定提交嗎?')">
		第1題:湖北省會(huì)是
		<input type="text" name="q1" />
		<br><br>
		第2題:宋朝開國(guó)皇帝是
		<br>
		<input type="radio" value="趙匡胤" name="q2">
		趙匡胤
		<input type="radio" value="朱元璋" name="q2">
		朱元璋
		<input type="radio" value="李淵" name="q2">
		李淵
		<br><br>
		第3題:四大名著有
		<br>
		<input type="checkbox" value="紅樓夢(mèng)" name="q3">
		紅樓夢(mèng)
		<input type="checkbox" value="水滸傳" name="q3">
		水滸傳
		<input type="checkbox" value="J2EE編程技術(shù)" name="q3">
		J2EE編程技術(shù)
		<br><br>
		<button type="submit">提交</button>
</form>
	
<%}%>

進(jìn)入頁(yè)面之前,會(huì)再次檢測(cè)用戶是否登錄,以防止用戶通過(guò)其他路徑訪問(wèn)到該頁(yè)面。

點(diǎn)擊提交時(shí),系統(tǒng)會(huì)提示是否提交,點(diǎn)擊確定后,系統(tǒng)后臺(tái)要做兩件事,第一件事就是注銷session,另一件事就是通過(guò)答案獲取相應(yīng)的分?jǐn)?shù),并且將用戶名和分?jǐn)?shù)保存。

4、提交頁(yè)面

用戶完成題目點(diǎn)擊提交后,系統(tǒng)會(huì)獲取用戶的答案,并與標(biāo)準(zhǔn)答案對(duì)比,獲取相應(yīng)的分?jǐn)?shù),同時(shí)使用application保存用戶名和成績(jī),這樣就可以在成績(jī)榜中顯示每個(gè)用戶的成績(jī)信息

<%!
Map<String, Integer> score_list = new HashMap<String, Integer>(); //存放用戶名+成績(jī) 
%>
<%
int score=0;
String q1=request.getParameter("q1");
String q2=request.getParameter("q2");
String[] q3=request.getParameterValues("q3");
 
if(q1!=null&&q1.equals("武漢")){	score+=10;	}
if(q2!=null&&q2.equals("趙匡胤")){	score+=10;	}
if(q3!=null&&q3.length==2&&q3[0].equals("紅樓夢(mèng)")&&q3[1].equals("水滸傳")){
	score+=10;	}
//out.print("<h2>你的成績(jī)=" + score + "</h2>");
 
score_list.put((String)session.getAttribute("username"), score);
application.setAttribute("scorelist", score_list);
response.sendRedirect("logout.jsp");
%>

 5、成績(jī)榜

成績(jī)榜通過(guò)application顯示所有登陸用戶的用戶名及成績(jī),并按照成績(jī)進(jìn)行排序‘'

<h1>成績(jī)榜</h1>
<%!
//降序排序
public <K, V extends Comparable<? super V>> Map<K, V> sortByValueDescending(Map<K, V> map)
 {
  List<Map.Entry<K, V>> list = new LinkedList<Map.Entry<K, V>>(map.entrySet());
  Collections.sort(list, new Comparator<Map.Entry<K, V>>()
  {
   
   public int compare(Map.Entry<K, V> o1, Map.Entry<K, V> o2)
   {
    int compare = (o1.getValue()).compareTo(o2.getValue());
    return -compare;
   }
  });
 
  Map<K, V> result = new LinkedHashMap<K, V>();
  for (Map.Entry<K, V> entry : list) {
   result.put(entry.getKey(), entry.getValue());
  }
  return result;
 }
%>
<%
if(application.getAttribute("scorelist")==null){
	out.print("<h3>沒(méi)有成績(jī)</h3>");
}
else{ //遍歷顯示所有成績(jī)(Map遍歷)
	Map<String, Integer> score_list= (Map<String, Integer>)application.getAttribute("scorelist");
	score_list=sortByValueDescending(score_list);
	Set s=score_list.keySet();
	Iterator it=s.iterator();
	while(it.hasNext()){
		String username=(String)it.next();
		int score=score_list.get(username);
		out.print("<h3>"+username+":"+score+"</h3>");
	}	
}
%>

 6、完整流程

到此這篇關(guān)于使用JSP技術(shù)實(shí)現(xiàn)一個(gè)簡(jiǎn)單的在線測(cè)試系統(tǒng)的實(shí)例詳解的文章就介紹到這了,更多相關(guān)JSP技術(shù)實(shí)現(xiàn)一個(gè)簡(jiǎn)單的在線測(cè)試系統(tǒng)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論