《Java Web程式設計》課程設計
學生管理系統
完成日期: 2018年12月26日
1 專案引言
1.1 專案簡介
學生入校後,我們需要管理這些學生,那麼就需要我們對這些學生進行很多的操作,此時我們學校對學生有條理的管理,包括一些基本資訊的記錄,就方便了學生的資訊管理。
1.2 使用技術
這是一個學生管理系統,應用的是SSH框架Spring+SpringMVC+Hibernate的專案,
運用的知識:
spring,springmvc,hibernate,Oracle
-
- 基本資料庫知識Oracle
-
- Spring+SpringMVC+Hibernate
-
- (重點)框架的MVC設計模式的應用
-
- 部分前端程式碼(CSS和JavaScript的應用)
1.3 開發環境
作業系統:Win10系統
開發語言:JavaEE,JavaWeb。
開發工具:MyEclipse Professional 2014, navicat
2 需求分析
1)功能介紹:
-
- 增刪改查學生。(test測試類中實現以及在jsp頁面實現修改和刪除)
-
- 增刪改查頁面顯示當前學生資訊(session裡獲取)
-
- 頁面時間自動更新功能
-
- 部分前端程式碼
(3)專案構建
專案分包:MVC架構
controller:控制層,寫SpringMvc的action
dao:資料層,Hibernate對資料的操作
entity:實體類和相應的*.hbm.xml(hibernate的類配置檔案)
servicesDao:業務Dao,對單筆Dao進行業務封裝
utils:工具類
3 概要設計
3.1 功能模組圖
增刪改查學生
增刪改查頁面顯示當前使用者資訊(session裡獲取)
時間更新
- - 部分前端程式碼
如圖3-1所示:
實現頁面顯示:
註冊頁面
登入頁面:
系統主頁面:
1 系統實現
思路:
實現原始碼:
1 package entity; 2 3 import java.io.Serializable; 4 //實現序列化介面 5 //實體類 6 public class Student implements Serializable{ 7 //要與表中欄位一一對應 8 private Integer id; 9 private String name; 10 private String password; 11 private String truename; 12 private String sex; 13 public Integer getId() { 14 return id; 15 } 16 public void setId(Integer id) { 17 this.id = id; 18 } 19 public String getName() { 20 return name; 21 } 22 public void setName(String name) { 23 this.name = name; 24 } 25 public String getPassword() { 26 return password; 27 } 28 public void setPassword(String password) { 29 this.password = password; 30 } 31 public String getTruename() { 32 return truename; 33 } 34 public void setTruename(String truename) { 35 this.truename = truename; 36 } 37 public String getSex() { 38 return sex; 39 } 40 public void setSex(String sex) { 41 this.sex = sex; 42 } 43 @Override 44 public String toString() { 45 return "Student [id=" + id + ", name=" + name + ", password=" 46 + password + ", truename=" + truename + ", sex=" + sex + "]"; 47 } 48 public Student(Integer id, String name, String password, String truename, 49 String sex) { 50 super(); 51 this.id = id; 52 this.name = name; 53 this.password = password; 54 this.truename = truename; 55 this.sex = sex; 56 } 57 public Student() { 58 super(); 59 } 60 61 62 }
1 package dao; 2 3 import java.sql.Date; 4 import java.util.List; 5 6 import entity.Student; 7 // DAO層 8 public interface StudentDAO { 9 //新增一條資料到資料庫中 10 public void insert (Student stu); 11 //查詢所有資料 12 public List<Student> queryall(); 13 //查詢單條資料 14 public Student query(String name); 15 //刪除單條資料 16 public void delete(Integer id); 17 //修改一條資料 18 public void update(Student stu); 19 //查詢單條資料 20 public Student queryone(Integer id); 21 //展示日期 22 public Date date(); 23 }
Mapper:
1 <?xml version="1.0" encoding="UTF-8"?> 2 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > 3 <mapper namespace="dao.StudentDAO"> 4 <insert id="insert" parameterType="student"> 5 <selectKey order="BEFORE" resultType="int" keyProperty="id"> 6 select student_sql.nextval from dual 7 </selectKey> 8 insert into student values(#{id},#{name},#{password},#{truename},#{sex}) 9 </insert> 10 <select id="queryall" resultType="student"> 11 select * from student 12 </select> 13 <!-- 查詢單挑資料 --> 14 <select id="query" resultType="student"> 15 select * from student where name=#{name} 16 </select> 17 <delete id="delete" parameterType="java.lang.Integer"> 18 delete from student where id=#{id} 19 </delete> 20 <!-- 修改一條資料 --> 21 <update id="update" parameterType="student"> 22 update student set name=#{name},password=#{password},truename=#{truename},sex=#{sex} where id=#{id} 23 </update> 24 <!-- 查詢單個物件 --> 25 <select id="queryone" resultType="student" parameterType="java.lang.Integer"> 26 select * from student where id=#{id} 27 </select> 28 <select id="date" resultType="java.sql.Date"> 29 select sysdate from dual 30 </select> 31 </mapper>
Service:
1 package service; 2 3 import java.util.List; 4 5 import entity.Student; 6 7 public interface StudentService { 8 //註冊賬戶 9 public void regester(Student stu); 10 //展示所有資料 11 public List<Student> showall(); 12 //登入使用者 13 public Student login(String name); 14 //刪除一個使用者 15 public void delete(Integer id); 16 //修改資料 17 public void update(Student stu); 18 //查詢單條資料 19 public Student query(Integer id); 20 //查詢日期 21 public String found(); 22 }
Serviceimpl:
1 package service; 2 3 import java.text.SimpleDateFormat; 4 import java.util.List; 5 6 import org.springframework.beans.factory.annotation.Autowired; 7 import org.springframework.stereotype.Service; 8 import org.springframework.transaction.annotation.Transactional; 9 10 import dao.StudentDAO; 11 import entity.Student; 12 13 @Service 14 //為原始類物件新增事務(額外功能) 15 @Transactional 16 public class StudentServiceimpl implements StudentService{ 17 /* 18 * 原始類物件:原始方法,呼叫dao和編寫邏輯程式碼 19 * */ 20 //將DAO介面定義成這個類中的成員變數 21 @Autowired 22 private StudentDAO dao; 23 24 public StudentDAO getDao() { 25 return dao; 26 } 27 //註冊一條資料 28 public void setDao(StudentDAO dao) { 29 this.dao = dao; 30 } 31 32 public void regester(Student stu){ 33 System.out.println(stu); 34 dao.insert(stu); 35 } 36 37 //展示所有資料 38 public List<Student> showall(){ 39 List<Student> list = dao.queryall(); 40 return list; 41 } 42 43 //註冊方法 44 public Student login(String name){ 45 Student s = dao.query(name); 46 return s; 47 } 48 49 //刪除一條資料 50 public void delete(Integer id){ 51 dao.delete(id); 52 } 53 54 //修改一條資料 55 public void update(Student stu){ 56 dao.update(stu); 57 } 58 59 //查詢一條資料 60 public Student query(Integer id){ 61 Student s = dao.queryone(id); 62 return s; 63 } 64 65 //展示日期 66 public String found(){ 67 java.sql.Date date = dao.date(); 68 //轉換成為java date 69 java.util.Date da = new java.util.Date(date.getTime()); 70 SimpleDateFormat Format = new SimpleDateFormat("yyyy-MM-dd"); 71 String s = Format.format(da); 72 return s; 73 } 74 }
Controller層
Student:
1 package action; 2 3 import java.util.List; 4 5 import javax.servlet.http.HttpServletRequest; 6 7 import org.springframework.beans.factory.annotation.Autowired; 8 import org.springframework.stereotype.Controller; 9 import org.springframework.web.bind.annotation.RequestMapping; 10 11 import entity.Student; 12 import service.StudentService; 13 14 //新增@Controller註解指定這個類物件是我們的控制器 15 @Controller 16 //為控制器新增url訪問路徑名稱 17 @RequestMapping("/student") 18 public class StudentController { 19 /* 20 * 1.收集資料 2.呼叫service層方法 3.流程跳轉 21 */ 22 @Autowired 23 private StudentService service; 24 25 public StudentService getService() { 26 return service; 27 } 28 29 public void setService(StudentService service) { 30 this.service = service; 31 } 32 33 @RequestMapping("/add") 34 public String add(Student stu){ 35 System.out.println("---------------------------"); 36 System.out.println(stu); 37 System.out.println(service); 38 service.regester(stu); 39 System.out.println("---------------------------"); 40 return "login"; 41 } 42 43 //展示所有資料到jsp頁面上 44 @RequestMapping("/show") 45 public String show(HttpServletRequest request){ 46 System.out.println("-----------------------------"); 47 List<Student> list = service.showall(); 48 request.setAttribute("list", list); 49 System.out.println("-----sfhfgthftg--------------------------"); 50 return "emplist"; 51 } 52 53 //登入控制器 54 @RequestMapping("/login") 55 public String login(Student stu,HttpServletRequest request,String code) { 56 System.out.println("--------------------------"); 57 //通過頁面傳來的name 去資料庫中查詢一個物件返回 58 Student student = service.login(stu.getName()); 59 //存入一個標記到作用域中,作為強制登入的判斷條件 60 request.getSession().setAttribute("key",student); 61 // 判斷student物件是否為空 62 if (student != null) { 63 if(request.getSession().getAttribute("code").equals(code)){ 64 if (student.getPassword().equals(stu.getPassword())) { 65 System.out.println("_---------------登入成功"); 66 return "forward:/student/show.do"; 67 } else { 68 System.out.println("密碼錯誤-----------------"); 69 return "login"; 70 } 71 }else{ 72 System.out.println("驗證碼錯誤===================="); 73 return "login"; 74 } 75 } else { 76 System.out.println("============================使用者不存在"); 77 return "register"; 78 } 79 80 } 81 82 // 刪除一條資料 83 @RequestMapping("/delete") 84 public String delete(int id,HttpServletRequest request){ 85 if(request.getSession().getAttribute("key")!=null){ 86 service.delete(id); 87 return "forward:/student/show.do";}else{ 88 return "login"; 89 } 90 } 91 92 //修改一條資料 93 @RequestMapping("/update") 94 public String update(Student stu){ 95 service.update(stu); 96 return "forward:/student/show.do"; 97 } 98 //查詢單個物件,並存入作用域跳轉到修改頁面 99 @RequestMapping("/select") 100 public String select(HttpServletRequest request){ 101 String i = request.getParameter("id"); 102 //字串轉換int 103 int id = Integer.parseInt(i); 104 Student student = service.query(id); 105 request.setAttribute("student",student); 106 return "updateEmp"; 107 } 108 }
Code:
1 package action; 2 3 import java.awt.image.BufferedImage; 4 import java.io.IOException; 5 import java.io.PrintWriter; 6 7 import javax.imageio.ImageIO; 8 import javax.imageio.stream.ImageOutputStream; 9 import javax.servlet.ServletOutputStream; 10 import javax.servlet.http.HttpServletResponse; 11 import javax.servlet.http.HttpSession; 12 13 import org.springframework.stereotype.Controller; 14 import org.springframework.web.bind.annotation.RequestMapping; 15 16 import util.SecurityCode; 17 import util.SecurityImage; 18 19 //新增註解使這個類物件成為控制器 20 @Controller 21 @RequestMapping("/code") 22 public class CodeController { 23 //固定public String 24 @RequestMapping("/code") 25 public void img(HttpServletResponse response, HttpSession session) throws IOException { 26 // 獲得驗證碼字串 27 String cool = SecurityCode.getSecurityCode(); 28 // 將驗證碼字串存入到session作用域中,目的是為了判斷時有條件可依 29 session.setAttribute("code", cool); 30 // 將驗證碼字串組裝拼接成驗證碼圖片 31 BufferedImage image = SecurityImage.createImage(cool); 32 // 響應到客戶端 33 ServletOutputStream out = response.getOutputStream(); 34 // 列印輸出驗證碼到頁面中 35 ImageIO.write(image, "png", out); 36 } 37 }
Util
securityCode:
1 package util; 2 3 import java.util.Arrays; 4 5 /** 6 * 7 * @author others 8 * date:2014-8-26 下午2:17:19 9 * 描述:隨機生成驗證碼值:驗證碼串 10 */ 11 public class SecurityCode { 12 /** 13 * 驗證碼難度級別 14 * Simple-數字 15 * Medium-數字和小寫字母 16 * Hard-數字和大小寫字母 17 */ 18 public enum SecurityCodeLevel { 19 Simple, Medium, Hard 20 }; 21 /** 22 * 產生預設驗證碼,4位中等難度 23 * 24 * @return 25 */ 26 public static String getSecurityCode() { 27 return getSecurityCode(3, SecurityCodeLevel.Medium, false); 28 } 29 /** 30 * 產生長度和難度任意的驗證碼 31 * 32 * @param length 33 * @param level 34 * @param isCanRepeat 35 * @return 36 */ 37 private static String getSecurityCode(int length, SecurityCodeLevel level, boolean isCanRepeat) { 38 // 隨機抽取len個字元 39 int len = length; 40 // 字符集合(--除去易混淆的數字0,1,字母l,o,O) 41 char[] codes = { 42 '2', '3', '4', '5', '6', '7', '8', '9', 43 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'm', 'n', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 44 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' 45 }; 46 // 根據不同難度擷取字串 47 if (level == SecurityCodeLevel.Simple) { 48 codes = Arrays.copyOfRange(codes, 0, 10); 49 } else if (level == SecurityCodeLevel.Medium) { 50 codes = Arrays.copyOfRange(codes, 0, 36); 51 } 52 // 字符集和長度 53 int n = codes.length; 54 // 丟擲執行時異常 55 if (len > n && isCanRepeat == false) { 56 throw new RuntimeException(String.format("呼叫SecurityCode.getSecurityCode(%1$s,%2$s,%3$s)出現異常," + "當isCanRepeat為%3$s時,傳入引數%1$s不能大於%4$s", len, level, isCanRepeat, n)); 57 } 58 // 存放抽取出來的字元 59 char[] result = new char[len]; 60 // 判斷能否出現重複字元 61 if (isCanRepeat) { 62 for (int i = 0; i < result.length; i++) { 63 // 索引0 and n-1 64 int r = (int) (Math.random() * n); 65 // 將result中的第i個元素設定為code[r]存放的數值 66 result[i] = codes[r]; 67 } 68 } else { 69 for (int i = 0; i < result.length; i++) { 70 // 索引0 and n-1 71 int r = (int) (Math.random() * n); 72 // 將result中的第i個元素設定為code[r]存放的數值 73 result[i] = codes[r]; 74 // 必須確保不會再次抽取到那個字元,這裡用陣列中最後一個字元改寫code[r],並將n-1 75 codes[r] = codes[n - 1]; 76 n--; 77 } 78 } 79 return String.valueOf(result); 80 } 81 public static void main(String[] args) { 82 System.out.println(SecurityCode.getSecurityCode()); 83 } 84 }
securityImage:
1 package util; 2 3 import java.awt.Color; 4 import java.awt.Font; 5 import java.awt.Graphics2D; 6 import java.awt.image.BufferedImage; 7 import java.util.Random; 8 9 public class SecurityImage { 10 /** 11 * 生成驗證碼圖片 12 * 13 * @param securityCode 14 * 15 * @return 16 * 17 */ 18 public static BufferedImage createImage(String securityCode) { 19 20 int codeLength = securityCode.length();// 驗證碼長度 21 22 int fontSize = 30;// 字型大小 23 24 int fontWidth = fontSize + 1; 25 26 // 圖片寬高 27 28 int width = codeLength * fontWidth + 4; 29 30 int height = fontSize * 1 + 1; 31 32 // 圖片 33 34 BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); 35 36 Graphics2D g = image.createGraphics(); 37 38 g.setColor(Color.WHITE);// 設定背景色 39 40 g.fillRect(0, 0, width, height);// 填充背景 41 42 g.setColor(Color.LIGHT_GRAY);// 設定邊框顏色 43 44 g.setFont(new Font("Arial", Font.BOLD, height - 2));// 邊框字型樣式 45 46 g.drawRect(0, 0, width - 1, height - 1);// 繪製邊框 47 48 // 繪製噪點 49 50 Random rand = new Random(); 51 52 g.setColor(Color.LIGHT_GRAY); 53 54 for (int i = 0; i < codeLength * 6; i++) { 55 56 int x = rand.nextInt(width); 57 58 int y = rand.nextInt(height); 59 60 g.drawRect(x, y, 1, 1);// 繪製1*1大小的矩形 61 62 } 63 64 // 繪製驗證碼 65 66 int codeY = height - 10; 67 68 g.setColor(new Color(19, 148, 246)); 69 70 g.setFont(new Font("Georgia", Font.BOLD, fontSize)); 71 for (int i = 0; i < codeLength; i++) { 72 double deg = new Random().nextDouble() * 20; 73 g.rotate(Math.toRadians(deg), i * 16 + 13, codeY - 7.5); 74 g.drawString(String.valueOf(securityCode.charAt(i)), i * 16 + 5, codeY); 75 g.rotate(Math.toRadians(-deg), i * 16 + 13, codeY - 7.5); 76 } 77 78 g.dispose();// 關閉資源 79 80 return image; 81 82 } 83 84 }
Test:
1 package test; 2 3 import java.util.List; 4 5 import org.junit.Test; 6 import org.springframework.context.ApplicationContext; 7 import org.springframework.context.support.ClassPathXmlApplicationContext; 8 9 import service.StudentService; 10 import dao.StudentDAO; 11 import entity.Student; 12 13 public class StudentTest { 14 @Test 15 public void test(){ 16 ApplicationContext ctx = new ClassPathXmlApplicationContext("/applicationContext.xml"); 17 //通過介面名首字母小寫作為beanid拿到的就是介面的實現類物件 18 StudentDAO dao = (StudentDAO)ctx.getBean("studentDAO"); 19 //dao.insert(new Student(10,"張明明","zmm","張明明","男")); 20 /*Student s = new Student(); 21 s.setId(11); 22 s.setName("樊小明"); 23 s.setPassword("fxm"); 24 dao.insert(s);*/ 25 /*List<Student> list = dao.queryall(); 26 for(Student student : list){ 27 System.out.println(student); 28 }*/ 29 //Student s = dao.query("張玉賢"); 30 //System.out.println(s); 31 //dao.delete(17); 32 dao.update(new Student(1,"賈克斯","jks","jia","男")); 33 //Student s = dao.queryone(8); 34 //System.out.println(s); 35 36 } 37 @Test 38 public void test2(){ 39 ApplicationContext ctx = new ClassPathXmlApplicationContext("/applicationContext.xml"); 40 StudentService s = (StudentService)ctx.getBean("studentServiceimpl"); 41 //s.regester(new Student(15,"金克斯","jks")); 42 /*List<Student> list = s.showall(); 43 for(Student student : list){ 44 System.out.println(student); 45 }*/ 46 //s.update(new Student(19,"老司機","lsj")); 47 //String ss = s.found(); 48 //System.out.println(ss); 49 50 51 } 52 }
jsp
Register:
1 <%@page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%> 2 <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 3 <c:set var="baseurl" value="${pageContext.request.contextPath}"></c:set> 4 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 5 <html> 6 <head> 7 <title>regist</title> 8 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 9 <link rel="stylesheet" type="text/css" href="${baseurl}/css/style.css" /> 10 </head> 11 <body> 12 <div id="wrap"> 13 <div id="top_content"> 14 <div id="header"> 15 <div id="rightheader"> 16 <p> 17 <script type="text/javascript"> 18 var date=new Date(); 19 //toLocaleString() 獲取本地時間格式的方法 20 document.write(date.toLocaleString()); 21 document.write("<hr size='3' color='blue'>"); 22 </script><br /> 23 </p> 24 </div> 25 <div id="topheader"> 26 <h1 id="title"> 27 <a href="#">main</a> 28 </h1> 29 </div> 30 <div id="navigation"></div> 31 </div> 32 <div id="content"> 33 <p id="whereami"></p> 34 <h1>註冊</h1> 35 <form action="${pageContext.request.contextPath}/student/add.do" 36 method="post"> 37 <table cellpadding="0" cellspacing="0" border="0" 38 class="form_table"> 39 <tr> 40 <td valign="middle" align="right">使用者名稱:</td> 41 <td valign="middle" align="left"><input type="text" 42 class="inputgri" name="name" /></td> 43 </tr> 44 <tr> 45 <td valign="middle" align="right">真實姓名:</td> 46 <td valign="middle" align="left"><input type="text" 47 class="inputgri" name="truename" /></td> 48 </tr> 49 <tr> 50 <td valign="middle" align="right">密碼:</td> 51 <td valign="middle" align="left"><input type="password" 52 class="inputgri" name="password" /></td> 53 </tr> 54 <tr> 55 <td valign="middle" align="right">性別:</td> 56 <td valign="middle" align="left">男 <input type="radio" 57 class="inputgri" name="sex" value="男" checked="checked" /> 女 <input 58 type="radio" class="inputgri" name="sex" value="女" /> 59 </td> 60 </tr> 61 62 </table> 63 <p> 64 <input type="submit" class="button" value="Submit »" /> 65 </p> 66 </form> 67 </div> 68 </div> 69 <div id="footer"> 70 <div id="footer_bg">ABC@126.com</div> 71 </div> 72 </div> 73 </body> 74 </html>
Login:
1 <%@page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%> 2 <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 3 <c:set var="baseurl" value="${pageContext.request.contextPath}"></c:set> 4 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 5 <html> 6 <head> 7 <title>login</title> 8 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 9 <link rel="stylesheet" type="text/css" href="${baseurl}/css/style.css" /> 10 </head> 11 12 <body> 13 <div id="wrap"> 14 <div id="top_content"> 15 <div id="header"> 16 <div id="rightheader"> 17 <p> 18 <script type="text/javascript"> 19 var date=new Date(); 20 //toLocaleString() 獲取本地時間格式的方法 21 document.write(date.toLocaleString()); 22 document.write("<hr size='3' color='blue'>"); 23 </script><br /> 24 </p> 25 </div> 26 <div id="topheader"> 27 <h1 id="title"> 28 <a href="#">main</a> 29 </h1> 30 </div> 31 <div id="navigation"></div> 32 </div> 33 <div id="content"> 34 <p id="whereami"></p> 35 <h1>login</h1> 36 <form action="${pageContext.request.contextPath}/student/login.do" 37 method="post"> 38 <table cellpadding="0" cellspacing="0" border="0" 39 class="form_table"> 40 <tr> 41 <td valign="middle" align="right">username:</td> 42 <td valign="middle" align="left"><input type="text" 43 class="inputgri" name="name" /></td> 44 </tr> 45 <tr> 46 <td valign="middle" align="right">password:</td> 47 <td valign="middle" align="left"><input type="password" 48 class="inputgri" name="password" /></td> 49 </tr> 50 <tr> 51 <td valign="middle" align="right">驗證碼:<img id="num" src="${pageContext.request.contextPath}/code/code.do" /></td> 52 <td> <input type="text" name="code" /></td> 53 </tr> 54 </table> 55 <p align="left"> 56 <input type="submit" class="button" value="登陸 »" 57 style="height: 26px; " /> 58 </p> 59 </form> 60 </div> 61 </div> 62 <div id="footer"> 63 <div id="footer_bg">ABC@126.com</div> 64 </div> 65 </div> 66 </body> 67 </html>
Update:
1 <%@page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%> 2 <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 3 <c:set var="baseurl" value="${pageContext.request.contextPath}"></c:set> 4 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 5 <html> 6 <head> 7 <title>update Emp</title> 8 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 9 <link rel="stylesheet" type="text/css" href="${baseurl}/css/style.css" /> 10 </head> 11 12 <body> 13 <div id="wrap"> 14 <div id="top_content"> 15 <div id="header"> 16 <div id="rightheader"> 17 <p> 18 <script type="text/javascript"> 19 var date=new Date(); 20 //toLocaleString() 獲取本地時間格式的方法 21 document.write(date.toLocaleString()); 22 document.write("<hr size='3' color='blue'>"); 23 </script><br /> 24 </p> 25 </div> 26 <div id="topheader"> 27 <h1 id="title"> 28 <a href="#">Main</a> 29 </h1> 30 </div> 31 <div id="navigation"></div> 32 </div> 33 <div id="content"> 34 <p id="whereami"></p> 35 <h1>updateEmp info:</h1> 36 <form action="${pageContext.request.contextPath}/student/update.do" 37 method="post"> 38 <table cellpadding="0" cellspacing="0" border="0" 39 class="form_table"> 40 <tr> 41 <td valign="middle" align="right">id:</td> 42 <td valign="middle" align="left"><input type="text" 43 class="inputgri" name="id" value="${requestScope.student.id}" readonly="readonly"/></td> 44 </tr> 45 <tr> 46 <td valign="middle" align="right">name:</td> 47 <td valign="middle" align="left"><input type="text" 48 class="inputgri" name="name" value="${requestScope.student.name}" /></td> 49 </tr> 50 <tr> 51 <td valign="middle" align="right">truename:</td> 52 <td valign="middle" align="left"><input type="text" 53 class="inputgri" name="truename" 54 value="${requestScope.student.truename}" /></td> 55 </tr> 56 <tr> 57 <td valign="middle" align="right">password:</td> 58 <td valign="middle" align="left"><input type="text" 59 class="inputgri" name="password" 60 value="${requestScope.student.password}" /></td> 61 </tr> 62 <tr> 63 <td valign="middle" align="right">sex:</td> 64 <td valign="middle" align="left"><input type="text" 65 class="inputgri" name="sex" value="${requestScope.student.sex}" /></td> 66 </tr> 67 </table> 68 <p> 69 <input type="submit" class="button" value="修改" /> 70 </p> 71 </form> 72 </div> 73 </div> 74 <div id="footer"> 75 <div id="footer_bg">ABC@126.com</div> 76 </div> 77 </div> 78 </body> 79 </html>
Emplist:
1 <%@page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%> 2 <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 3 <c:set var="baseurl" value="${pageContext.request.contextPath}"></c:set> 4 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 5 <html> 6 <head> 7 <title>emplist</title> 8 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 9 <link rel="stylesheet" type="text/css" href="${baseurl}/css/style.css" /> 10 </head> 11 <body> 12 <div id="wrap"> 13 <div id="top_content"> 14 <div id="header"> 15 <div id="rightheader"> 16 <p> 17 <script type="text/javascript"> 18 var date=new Date(); 19 //toLocaleString() 獲取本地時間格式的方法 20 document.write(date.toLocaleString()); 21 document.write("<hr size='3' color='blue'>"); 22 </script><br /> 23 </p> 24 </div> 25 <div id="topheader"> 26 <h1 id="title"> 27 <a href="#">main</a> 28 </h1> 29 </div> 30 <div id="navigation"></div> 31 </div> 32 <div id="content"> 33 <p id="whereami"></p> 34 <h1>Welcome!</h1> 35 <h1>尊敬的使用者:${sessionScope.key.name}</h1> 36 <table class="table"> 37 <tr class="table_header"> 38 <td>ID</td> 39 <td>Name</td> 40 <td>Password</td> 41 <td>Truename</td> 42 <td>Sex</td> 43 <td>Operation</td> 44 </tr> 45 46 <c:forEach var="student" items="${list}"> 47 <tr> 48 <td>${student.id}</td> 49 <td>${student.name}</td> 50 <td>${student.password}</td> 51 <td>${student.truename}</td> 52 <td>${student.sex}</td> 53 <td> 54 <a href="${pageContext.request.contextPath}/student/delete.do?id=${student.id}">刪除</a> 55 <a href="${pageContext.request.contextPath}/student/select.do?id=${student.id}">修改</a> 56 </td> 57 </tr> 58 </c:forEach> 59 60 61 </table> 62 </div> 63 </div> 64 <div id="footer"> 65 <div id="footer_bg">ABC@126.com</div> 66 </div> 67 </div> 68 </body> 69 </html>
結束語:
剛開始接觸這個課題時,感覺很多問題接踵而至,不知所措,但是,在自己的努力和別人的幫助下下,還是成功了,心裡很開心,很充實。這個課題研究的意義是,對資料庫進行增刪改查操作,這個課題給我帶來了很大的收穫。我在當中也學到了很多精神,刻苦奮鬥,鍥而不捨。人生不會再有第二個大學,我很珍惜在大學裡的一切,也很懷念這一切。活在當下,珍惜當下,充實當下。
南陽理工學院
Nanyang Institute of Technology