Java課程設計—學生成績管理系統(201521123004-林藝如)


1.團隊課程設計博客

團隊課程設計博客鏈接

2.個人負責模塊或任務說明

①.Menu

  • Menu.jsp

    • 在頁面中給出提示,用HTML的<input.../>,
      與下一個跳轉頁面進行連接,即點擊后進入下一個頁面
  • MenuTeacher.jsp

    • 利用Menu.jsp進行具體化完善和修改,由於教師與學生的權限不同,將教師和學生的功能選擇進行區分

    • 教師:增、刪、改、查

    • 學生:改,查(個人)

    • 確認后跳轉到相應的頁面

②Login

  • Login.jsp

    • 通過賬號和密碼匹配正確后,進入Menu界面

    • 教師與學生分別位於不同的表中,需要分開處理

  • StudentLogin.jsp

    • 學生通過在頁面輸入學號密碼進行賬號登錄

    • 將輸入的學號在數據庫中進行查找,找到后進行密碼比較,一直即進入菜單界面

③Delete

  • Delete.jsp

    • 提示輸入需要刪除的學生學號
    • 確認后,通過delete(String stuno)方法,最后跳轉至刪除成功與否界面
  • DeleteSuccess.jsp

    • Delete頁面中的學號存在,顯示該學生信息;否則,提示找不到,刪除失敗

    • 返回菜單界面

3.自己的代碼提交記錄截圖

4.自己負責模塊或任務詳細說明

①Login----提示輸入賬戶和密碼進行登錄,教師與學生在不同的數據庫表中,教師的表名為teachers,內含賬號和密碼;學生的表名為students,內含學生個人信息與成績。

  • 登陸界面
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>學生登錄</title>
</head>
<body>
	<form name="postForm" action="LoginStuSuccess.jsp" method="post">
		<p>賬號 :<input type="text" name="stuno" /></p>
  		<p>密碼 :<input type="password" name="password" /></p>
		<input type="submit" value="登錄" />
	</form>
</body>
</html>
  • 登錄頁面

  • 登錄后(數據庫找到對應學號,比較密碼,成功即登錄,失敗即刷新重新輸入)
<%@ page language="java" import="java.util.*,StudentScore.*" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%> 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>學生登錄成功</title>
</head>
<body>
<form name="postForm" action="MenuStudent.jsp" method="post">
<%
    	StudentDao sdao = new StudentDaoJDBC();
    	String no = request.getParameter("stuno");
    	int stuno = Integer.parseInt(no);
    	String password = request.getParameter("password");
    	if(sdao.login(stuno,password)!=1){
    		response.sendRedirect("StudentLogin.jsp");
  
		}
    	else
    	{
    		
 %>
 <td>學號:<input type="text" id="a" name="stuno" value=<%=no%>></td>
    		<p>登陸成功!</p>
    	<input type="submit" value="Menu" />
    		<% 
    		}
			%>
</form>
</body>
</html>
  • 學生登錄成功進入菜單界面(登錄失敗刷新頁面重新輸入)

  • 登錄過程方法(可具體提示登錄失敗的原因,密碼錯誤或學號不存在)
		@Override
		public int login(int no, String password) {
			// TODO Auto-generated method stub
			int result=-1;
			Connection conn = null;
			PreparedStatement pstat = null;
			ResultSet rs = null;
			String sql = "select * from students where stuno=?";//表中有id和name這列
			try {
				conn = JDBCUtil.getConnection();
				pstat = conn.prepareStatement(sql);
				pstat.setInt(1,no);
				rs = pstat.executeQuery();
				int stu = 0;
				String stupassword=null;
				while(rs.next()){
					stupassword=rs.getString("password");
					stu=rs.getInt("stuno");
				}
				if(stu>0){
					if(stupassword.equals(password)){
						System.out.println("登錄成功!");
						result = 1;
						}
					else{
						System.out.println("登錄失敗,密碼錯誤!");
						}
				}else {
					System.out.println("登錄失敗,學號不存在!");
				}
			}catch (SQLException sqle) {
				sqle.printStackTrace();
			}catch(Exception e){
				e.printStackTrace();
			}finally{
				JDBCUtil.realeaseAll(rs,pstat, conn);
			}
			return result;
		}

②Menu----根據學生與老師的權限進行排版,(教師:增、刪、改、查; 學生:改,查(個人)),每一個選擇按鈕點擊之后進入到相應界面

  • 初步界面(未修訂)
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title> 菜單選項</title>
</head>
<body>
<form name="fm" method="post">
<p>功能選擇</p>
<p>1.錄入學生成績,點擊<input type="button" name="btn2" onclick="document.fm.action='EnterStudentScore.jsp';document.fm.submit();"
value="錄入"/></p>
<p>2.刪除學生信息,點擊<input type="button" name="btn1" onclick="document.fm.action='Delete.jsp';document.fm.submit();"
value="刪除"/></p>
<p>3.修改學生信息,點擊<input type="button" name="btn2" onclick="document.fm.action='UpdateView.jsp';document.fm.submit();"
value="修改"/></p>
<p>4.查找學生信息,點擊<input type="button" name="btn2" onclick="document.fm.action='findStudent.jsp';document.fm.submit();"
value="查找"/></p>
</form>
</body>
</html>
  • 老師界面
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title> 老師菜單</title>
</head>
<body>
<form name="fm" method="post">
<p>功能選擇</p>
<p>1.錄入學生成績,點擊<input type="button" name="btn2" onClick="document.fm.action='MenuCourse.jsp';document.fm.submit();"
value="錄入"/></p>
<p>2.刪除學生信息,點擊<input type="button" name="btn1" width="100" heigth="20" onClick="document.fm.action='Delete.jsp';document.fm.submit();"
value="刪除"/></p>
<p>3.修改學生信息,點擊<input type="button" name="btn2" onClick="document.fm.action='UpdateView1.jsp';document.fm.submit();"
value="修改"/></p>
<p>4.查找學生信息,點擊<input type="button" name="btn2" onClick="document.fm.action='findStudent.jsp';document.fm.submit();"
value="查找"/></p>
<p>5.所有學生信息,點擊<input type="button" name="btn2" onClick="document.fm.action='ShowStudentMessage.jsp';document.fm.submit();"
value="導出"/></p>
</form>
</body>
</html>

③Delete

  • delete方法(信息僅學號唯一,根據學號進行刪除操作)
@Override
		public int delete(String no) {
			// TODO Auto-generated method stub
	    	Connection conn = null;
	    	Statement st= null;
	    	ResultSet resultset=null;
			String sql = "delete from students where stuno="+no;
			int result = -1;
			try {
				conn = JDBCUtil.getConnection();
				st = conn.createStatement();
				int i=st.executeUpdate(sql);
			}catch (SQLException sqle) {
				sqle.printStackTrace();
			}catch(Exception e){
				e.printStackTrace();
			}finally{
				JDBCUtil.realeaseAll(null,st, conn);
			}
			return result;
		}
  • delete界面
<%@ page language="java" import="java.util.*,StudentScore.*" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>   
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>刪除學生</title>
</head>
<body>
 <form name="postForm" action="DeleteSuccess.jsp" method="post">
		<p>請輸入需要刪除的學生學號</p>
		<p>
			學號:<input type="text" name="stuno" />
		</p>
		<input type="submit" value="Delete" />
	</form>
</body>
</html>

  • delete成功或失敗
<%@ page language="java" import="java.util.*,StudentScore.*" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>刪除成功</title>
</head>
<body>
<form name="postForm" action="MenuTeacher.jsp" method="post">
 <%
    	StudentDao sdao = new StudentDaoJDBC();
    	String no = request.getParameter("stuno");
    	int s = sdao.delete(no);		
    %>
<p>刪除成功!返回菜單</p>
<input type="submit" value="MENU" />
</form>
</body>
</html>

5.課程設計感想

 通過這次課設,對數據庫,Dao,JDBC等認識加深了很多,不僅如此,還積累了一些課外的新知識;雖然過程中碰到許多令人崩潰和無語的問題,,在jsp與Java還有一些不熟悉的地方,所幸最終大部分問題都能解決;還有重要的一點是團隊協作很重要,有時候你忽略的小問題別人一眼就能發現,雖然我的能力不夠好,但是到最后看到自己的代碼(雖然不多)能在整個項目中運行還是很激動很開心的;遺憾的是時間緊,技術弱,沒能把想法更加完善出來。

Java課程設計


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM