考試系統--框架搭建
今天老師讓做了一個考試系統的框架
下面是執行成果部分:
下面是程式碼部分:
html:登入
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/css/bootstrap.min.css">
<script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdn.staticfile.org/popper.js/1.15.0/umd/popper.min.js"></script>
<script src="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script>
<title>登入</title>
<style type="text/css">
*{
padding:0px;
margin:0px;
}
.header{
width:100%;
height:120px;
background-color:lightgray;
text-align:center;
}
.container{
width:100%;
height:780px;
position:relative;
background-color:lightblue;
}
.login{
width:500px;
height:auto;
background-color:white;
position:absolute;
top:200px;
left:500px;
border-radius:8px;
}
label{
float:left;
width:100px;
margin-top:7px;
margin-right:5px;
}
.form-control{
width:60%;
}
.logtip{
padding-top:20px;
padding-bottom:20px;
border-bottom:2px solid red;
text-align:center;
}
.form-group{
margin-left:40px;
margin-top:40px;
}
.btn{
height:50px;
width:100px;
float:left;
border-radius:10px;
}
.logbtn{
margin-right:20px;
}
.btnbag{
margin-left:140px;
margin-right:140px;
height:50px;
overflow:hidden;
margin-top:30px;
margin-bottom:40px;
}
</style>
</head>
<body>
<div class="header"><h2>考試系統</h2></div>
<div class="container">
<div class="login">
<h2 class="logtip">登入</h2>
<form action="login_do" method="post">
<div class="form-group">
<label for="username">使用者名稱</label>
<input type="text" class="form-control" id="username" name="username">
</div>
<div class="form-group">
<label for="password">密碼</label>
<input type="password" class="form-control" id="password" name="password">
</div>
<div class="btnbag">
<input type="button" class="btn btn-primary logbtn" onclick="login()" value="登入">
<input type="button" class="btn btn-primary mangbtn" onclick="entermang()" value="進入管理">
</div>
</form>
</div>
</div>
<div class="footer"></div>
</body>
<script>
function login()
{
var username=$("#username").val();
var password=$("#password").val();
if(username==""||password=="")
alert("請將資訊填寫完整!");
else
{
$.post(
"login_do",
{username:username,
password:password},
function(data){
if(data=="yes")
{
alert("成功登陸!");
window.location="mainpage.jsp";
}
else
alert("使用者名稱或密碼錯誤!或使用者已被暫停使用!");
},
"text"
);
}
}
function entermang()
{
var username=$("#username").val();
var password=$("#password").val();
if(username==""||password=="")
alert("請將資訊填寫完整!");
else
{
$.post(
"login_do",
{username:username,
password:password},
function(data){
if(data=="yes")
{
alert("成功登陸!");
window.location="backmainpage.jsp";
}
else
alert("使用者名稱或密碼錯誤!或使用者已被暫停使用!");
},
"text"
);
}
}
</script>
</html>
主html:
<%@page import="com.official.util.DBUtil"%>
<%@page import="com.official.bean.Permission"%>
<%@page import="org.apache.jasper.tagplugins.jstl.core.ForEach"%>
<%@page import="java.util.ArrayList"%>
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/css/bootstrap.min.css">
<script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdn.staticfile.org/popper.js/1.15.0/umd/popper.min.js"></script>
<script src="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script>
<title>Insert title here</title>
<style type="text/css">
*{
padding:0px;
margin:0px;
}
.header{
width:100%;
height:120px;
background-color:lightblue;
text-align:center;
position:relative;
}
.contain{
width:100%;
height:780px;
position:relative;
background-color:lightblue;
}
.list-group{
width:15%;
float:left;
}
a{
text-decoration:none;
width:100%;
}
.list-group a:hover{
font-size:18px;
font-weight:bold;
}
.operation{
width:85%;
height:780px;
float:right;
}
iframe{
border:0px;
}
.loginfoshow{
position:absolute;
width:auto;
text-align:right;
bottom:5px;
right:5px;
}
.loginfoshow a
{
color:#D8D8D8;
cursor:pointer;
}
.loginfoshow a:hover
{
color:white;
}
.loginfoshow p{
float:left;
color:white;
}
</style>
<script>
function onload()
{
<%
Cookie[] cookies=request.getCookies();
String value="";
ArrayList<Permission> list=new ArrayList<>();
if(cookies!=null){
System.out.println("cookie的長度為:"+cookies.length);
for(int i=0;i<cookies.length;i++)
{
if(cookies[i].getName().equals("username"))
{
value=cookies[i].getValue();
}
if(cookies[i].getName().equals("pid"))
{
Permission permission=new Permission();
permission.setId(Integer.parseInt(cookies[i].getValue()));
list=DBUtil.getPermission(permission);
}
}
}
%>
$("#informationshow").text("當前登入賬戶:<%=value %>");
}
function exitlog(event)
{
var msg = "您確定要登出嗎?";
if (confirm(msg)==true){
event.href="http://localhost:8080/official-document/index.jsp";
}
else{
alert("操作取消!");
}
}
</script>
</head>
<body onload="onload()">
<div class="header">
<h2>考試系統</h2>
<div class="loginfoshow" id="userinfor">
<p id="informationshow"></p>
<a href="" onclick="exitlog(this)">[登出]</a>
</div>
</div>
<div class="contain">
<div class="list-group">
<%for(Permission s:list)
{
if(s.getPermission()==1){%>
<a id="1" href="writedoc.jsp?user=<%=value %>" class="list-group-item list-group-item-aciton" target="operation">期刊擬製</a>
<%}else if(s.getPermission()==2){ %>
<a id="2" href="getReceivedorNot?user=<%=value %>&type=received" class="list-group-item list-group-item-aciton" target="operation">建立考試基礎資訊</a>
<%}else if(s.getPermission()==3){ %>
<a id="3" href="showAll" class="list-group-item list-group-item-aciton" target="operation">制定試題</a>
<%}else if(s.getPermission()==5){ %>
<a id="5" href="getDoc?type=receive" class="list-group-item list-group-item-aciton" target="operation">期刊流轉</a>
<%}else if(s.getPermission()==6){ %>
<a id="6" href="queryDoc?type=all" class="list-group-item list-group-item-aciton" target="operation">制定考試資訊</a>
<%}else if(s.getPermission()==7){ %>
<a id="7" href="checkDoc?type=notchecked" class="list-group-item list-group-item-aciton" target="operation">稽核期刊</a>
<%}else if(s.getPermission()==8){ %>
<a id="8" href="fcheckDoc?type=notchecked" class="list-group-item list-group-item-aciton" target="operation">錄入參加考試的學生資訊</a>
<%}else if(s.getPermission()==9){ %>
<a id="9" href="fcheckDoc?type=notchecked" class="list-group-item list-group-item-aciton" target="operation">課程成績單</a>
<%}else if(s.getPermission()==10){ %>
<a id="10" href="fcheckDoc?type=notchecked" class="list-group-item list-group-item-aciton" target="operation">通知資料</a>
<%}else if(s.getPermission()==11){ %>
<a id="11" href="showAll" class="list-group-item list-group-item-aciton" target="operation">格式審查</a>
<%}else if(s.getPermission()==12){ %>
<a id="12" href="fcheckDoc?type=notchecked" class="list-group-item list-group-item-aciton" target="operation">內容查重</a>
<%}else if(s.getPermission()==13){ %>
<a id="13" href="showAll" class="list-group-item list-group-item-aciton" target="operation">考試說明</a>
<%}else if(s.getPermission()==14){ %>
<a id="14" href="fcheckDoc?type=notchecked" class="list-group-item list-group-item-aciton" target="operation">稿件評審</a>
<%}else if(s.getPermission()==15){ %>
<a id="15" href="showAll" class="list-group-item list-group-item-aciton" target="operation">稿件簽發</a>
<%}else if(s.getPermission()==16){ %>
<a id="16" href="fcheckDoc?type=notchecked" class="list-group-item list-group-item-aciton" target="operation">查詢稿件</a>
<%}else if(s.getPermission()==17){ %>
<a id="17" href="showAll" class="list-group-item list-group-item-aciton" target="operation">撤回稿件</a>
<%}else if(s.getPermission()==18){ %>
<a id="18" href="fcheckDoc?type=notchecked" class="list-group-item list-group-item-aciton" target="operation"></a>
<%}else if(s.getPermission()==19){ %>
<a id="19" href="fcheckDoc?type=notchecked" class="list-group-item list-group-item-aciton" target="operation">個人成績報告</a>
<%}else if(s.getPermission()==20){ %>
<a id="20" href="fcheckDoc?type=notchecked" class="list-group-item list-group-item-aciton" target="operation">通知資料</a>
<%}else if(s.getPermission()==21){ %>
<a id="21" href="fcheckDoc?type=notchecked" class="list-group-item list-group-item-aciton" target="operation">開始答題</a>
<%}
} %>
</div>
<div class="operation">
<iframe name="operation" src="" width="100%" height="100%" style="background-color: gray;"></iframe>
</div>
</div>
<div class="footer"></div>
</body>
</html>