<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                用jsp、javabean做了一個學生信息管理系統,雖然j2ee的框架很多,但是基礎仍然很重要。麻雀雖小五臟俱全,希望本博客對j2ee初學者有幫助,也是對自己知識的復習和整合。 ### 系統預覽: ### 管理員登錄界面 ![這里寫圖片描述](https://box.kancloud.cn/2016-02-26_56cfbdd7d6d2f.jpg "") ### 錄入信息界面 ![這里寫圖片描述](https://box.kancloud.cn/2016-02-26_56cfbdd803cf8.jpg "") ### 管理界面 ![這里寫圖片描述](https://box.kancloud.cn/2016-02-26_56cfbdd82fa07.jpg "") ### 修改學生信息 ![這里寫圖片描述](https://box.kancloud.cn/2016-02-26_56cfbdd85d066.jpg "") 系統比較簡單,有增刪改查四個基本功能。 源碼下載地址:[學生信息管理系統源碼] ([http://download.csdn.net/detail/napoay/9411126](http://download.csdn.net/detail/napoay/9411126)) 線上訪問地址:[http://120.27.46.201:8080/studentmanager](http://120.27.46.201:8080/studentmanager)(用戶名:admin,密碼:123456) ### 核心代碼 ### jdbc連接數據庫 ~~~ package cn.ac.ucas.conn; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; public class Conn { public Connection getConn() { Connection conn = null; try { Class.forName("com.mysql.jdbc.Driver"); String url="jdbc:mysql://127.0.0.1/student?useUicode=true&characterEncoding=utf-8"; String user="root"; String password="123456"; conn=DriverManager.getConnection(url, user, password); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); return null; } return conn; } } ~~~ ### 管理員登陸 在數據庫中有一張user表,有用戶名和密碼兩個字段,登錄時將用戶輸入的用戶名和密碼和數據庫中的管理員畢竟,用戶名和密碼輸入正確登錄成功。 #### login.jsp ~~~ <jsp:useBean id="user" class="cn.ac.ucas.model.User"></jsp:useBean> <jsp:useBean id="userservice" class="cn.ac.ucas.service.UserService"></jsp:useBean> <jsp:setProperty property="*" name="user" /> <% if (userservice.validUser(user)) { session.setAttribute("user", user); %> <jsp:forward page="main.jsp"></jsp:forward> <% } else { %> <jsp:forward page="index.jsp"></jsp:forward> <% } %> ~~~ #### 驗證用戶名和密碼 ~~~ public boolean validUser(User user) { try { pstmt = conn.prepareStatement("select * from user where username=?and password=?"); pstmt.setString(1, user.getUsername()); pstmt.setString(2, user.getPassword()); ResultSet rst = pstmt.executeQuery(); if (rst.next()) { return true; } else { return false; } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); return false; } } ~~~ ### 使用session 用戶名和密碼輸入正確的時候把user放到seesion中: ~~~ session.setAttribute("user", user); ~~~ 用戶名和密碼輸入不正確不能之間訪問登錄后的頁面,不然用戶直接輸入地址就可以訪問到管理頁面,登錄和不登錄沒有區別。下面試checklogin.jsp,需要登錄后訪問的頁面使用jsp:include包含在內,這樣如果session中沒有user信息返回到首頁,不能直接查看。 ~~~ <%@page import="cn.ac.ucas.model.User"%> <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <% User user= (User)session.getAttribute("user"); if(user==null){ %> <jsp:forward page="index.jsp"></jsp:forward> <% } %> ~~~ 退出時移出session ~~~ session.removeAttribute("user"); ~~~ ### 增 ~~~ public boolean addStu(Student student) { try { pstmt = conn.prepareStatement( "insert into Student(nickname,name,gender,birth,majority,course,interest,otherinfo)" + "values(?,?,?,?,?,?,?,?)"); pstmt.setString(1, student.getNickname()); pstmt.setString(2, student.getName()); pstmt.setByte(3, student.getGender()); pstmt.setString(4, student.getBirth()); pstmt.setString(5, student.getMajority()); pstmt.setString(6, student.getCourses()); pstmt.setString(7, student.getInterests()); pstmt.setString(8, student.getOtherinfo()); pstmt.executeUpdate(); return true; } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); return false; } } ~~~ ### 刪 ~~~ public boolean deleteStu(int id) { try { pstmt = conn.prepareStatement("delete from Student where id=?"); pstmt.setInt(1, id); pstmt.executeUpdate(); return true; } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); return false; } } ~~~ ### 改 ~~~ public boolean updateStu(Student student){ try { pstmt=conn.prepareStatement("update Student set nickname=?,name=?,gender=?,birth=?,majority=?,course=?,interest=?,otherinfo=? where id=?"); pstmt.setString(1, student.getNickname()); pstmt.setString(2, student.getName()); pstmt.setByte(3, student.getGender()); pstmt.setString(4, student.getBirth()); pstmt.setString(5, student.getMajority()); pstmt.setString(6, student.getCourses()); pstmt.setString(7, student.getInterests()); pstmt.setString(8, student.getOtherinfo()); pstmt.setInt(9, student.getId()); pstmt.executeUpdate(); return true; } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); return false; } } ~~~ ### 查 #### 查詢所有學生信息 ~~~ public List getAllStudent() { List stuList = new ArrayList(); try { pstmt = conn.prepareStatement("select * from Student"); ResultSet rst = pstmt.executeQuery(); while (rst.next()) { Student stu = new Student(); stu.setId(rst.getInt(1)); stu.setNickname(rst.getString(2)); stu.setName(rst.getString(3)); stu.setGender(rst.getByte(4)); stu.setBirth(rst.getString(5)); stu.setMajority(rst.getString(6)); if (rst.getString(7) != null) { stu.setCourse(rst.getString(7).split("&&")); } if (rst.getString(8) != null) { stu.setInterest(rst.getString(8).split("&&")); } stu.setOtherinfo(rst.getString(9)); stuList.add(stu); } return stuList; } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); return null; } } ~~~ #### 查詢單個學生信息 ~~~ public Student getStuById(int id) { try { pstmt = conn.prepareStatement("select * from Student where id = ?"); pstmt.setInt(1, id); ResultSet rst = pstmt.executeQuery(); if(rst.next()){ Student stu=new Student(); stu.setId(rst.getInt(1)); stu.setNickname(rst.getString(2)); stu.setName(rst.getString(3)); stu.setGender(rst.getByte(4)); stu.setBirth(rst.getString(5)); stu.setMajority(rst.getString(6)); if (rst.getString(7) != null) { stu.setCourse(rst.getString(7).split("&&")); } if (rst.getString(8) != null) { stu.setInterest(rst.getString(8).split("&&")); } stu.setOtherinfo(rst.getString(9)); return stu; } return null; } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); return null; } } ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看