基于java+jsp+servlet的学生信息管理系统

源码编号:F-B05

项目类型:Java web项目(开源免费)

项目名称:基于JSP+Servlet的学生信息管理系统

项目架构:B/S架构

开发语言:Java语言

前端技术:HTML、CSS、JS、JQuery等技术

后端技术:JSP、Servlet、JDBC等技术

运行环境:Win10、JDK1.8

数  据  库:MySQL5.7及以上

运行服务器:Tomcat8.0及以上

运行工具:Eclipse\MYEclipse\IDEA。

项目简介:登录注册、增删改查学生信息,可能部分功能未实现,请自行修改​完善,本项目仅供参考!

项目骨架

项目部分运行截图

以下是部分代码

package com.rj.servlet;

import com.rj.service.UserService;
import com.rj.pojo.User;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

public class UserServlet extends HttpServlet {
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
        doPost(request,response);
    }
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
        String action = request.getParameter("action");    //获取action参数值
        if (action == null)
            action = "";

        if (action.equals("userLogin"))                    //触发了“用户登录”请求
        {
            String user = request.getParameter("userID");
            String pwd = request.getParameter("userPassword");
            String category = request.getParameter("userCategory");
            User user1 = new User();
            user1.setUserID(user);
            user1.setUserCategory(category);
            request.getSession().setAttribute("us",user1);
            try {
                if(new UserService().LoginDeal(user,pwd,category)){
                    response.sendRedirect("main.jsp");
                } else
                    response.sendRedirect("index.jsp");
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            } catch (SQLException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            } catch (InstantiationException e) {
                e.printStackTrace();
            }
        }

        if (action.equals("userRegister"))                    //触发了“用户注册”请求
        {
            String user = request.getParameter("userID");
            String pwd = request.getParameter("userPassword");
            try {
                if(new UserService().RegisterDeal(user,pwd)==1){
                    response.sendRedirect("index.jsp");
                }else
                    response.sendRedirect("index.jsp");
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            } catch (SQLException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            } catch (InstantiationException e) {
                e.printStackTrace();
            }
        }

    }
}







dao层代码

package com.rj.service;

import com.rj.pojo.User;

import java.io.UnsupportedEncodingException;
import java.sql.*;
import java.util.ArrayList;

public class UserService {
    public  boolean LoginDeal(String user,String pwd,String category) throws ClassNotFoundException, SQLException, IllegalAccessException, InstantiationException {
        ConnDB conndb = new ConnDB();
        ResultSet rs = conndb.getResult("select * from tb_user where userID=? and userPassWord=? and userCategory=?",new String[]{user,pwd,category});
        if(rs.next()) {
            return true;
        }else {
            return false;
        }
    }

    public  int RegisterDeal(String user,String pwd) throws UnsupportedEncodingException, ClassNotFoundException, SQLException, IllegalAccessException, InstantiationException {
        ConnDB conndb = new ConnDB();
        int rtn= conndb.executeIDU("insert into tb_user (userID,userPassword,userCategory) values(?,?,?)",new String[]{user,pwd, String.valueOf(0)});
        return rtn;
    }

    public ArrayList FindAll() throws ClassNotFoundException, SQLException, InstantiationException, IllegalAccessException {
        ArrayList userList = new ArrayList();
        ConnDB conndb = new ConnDB();
        ResultSet rs = conndb.getResult("select * from tb_user where userCategory=?",new String[]{String.valueOf(0)});
        while(rs.next()){
            User user = new User();
            user.setId(rs.getString("id"));
            user.setUserID(rs.getString("userID"));
            user.setUserPassword(rs.getString("userPassword"));
            user.setUserCategory(rs.getString("userCategory"));
            userList.add(user);
        }
        return userList;
    }

    public  int userDel(String id) throws UnsupportedEncodingException, ClassNotFoundException, SQLException, IllegalAccessException, InstantiationException {
        ConnDB conndb = new ConnDB();
        int rtn= conndb.executeIDU("delete from tb_user where id=?",new String[]{id});
        return rtn;
    }

    public  int userInitPwd(String id) throws UnsupportedEncodingException, ClassNotFoundException, SQLException, IllegalAccessException, InstantiationException {
        ConnDB conndb = new ConnDB();
        int rtn= conndb.executeIDU("update tb_user set userPassword=123456 where id=?",new String[]{id});
        return rtn;
    }

    public  boolean userCheck(String user) throws ClassNotFoundException, SQLException, IllegalAccessException, InstantiationException {
        ConnDB conndb = new ConnDB();
        ResultSet rs = conndb.getResult("select * from tb_user where userID=?",new String[]{user});
        if(rs.next()) {
            return true;
        }else {
            return false;
        }
    }
}

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值