基于javaweb+jsp的户籍管理系统

基于javaweb+jsp的户籍管理系统

JavaWeb JavaBean JSP MVC MySQL Tomcat JavaScript Bootstrap

基础JSP+Servlet或JSP+SSM(Spring、SpringMVC、MyBatis)框架或JSP+SSM+Maven(pom.xml)框架或SpringBoot…均可

开发工具:eclipse/idea/myeclipse/sts等均可配置运行

适用

课程设计,大作业,毕业设计,项目练习,学习演示等

        if (document.getElementById("householdArea").value.trim().length == 0) {
            alert("所在区不能为空!");
            return false;
        }
        if (document.getElementById("householdHouseno").value.trim().length == 0) {
            alert("房屋号不能为空!");
            return false;
        }
        if (document.getElementById("householdUnit").value.trim().length == 0) {
            alert("单元不能为空!");
            return false;
        }
        if (document.getElementById("householdStyle").value.trim().length == 0) {

    //@Override
    public User get(Serializable id) {
        User vo = null;
        try {
            Connection c = Util.getConnection();
            Statement s = c.createStatement();
            String sql = "select * from `t_user` where id = " + id;
            ResultSet rs = s.executeQuery(sql);
            if (rs.next()) {
                vo = new User();
                vo.setId(rs.getLong("id"));
                vo.setUsername(rs.getString("username"));
                vo.setPassword(rs.getString("password"));
                vo.setRealName(rs.getString("real_name"));
        }
        Map<String, Object> result = new HashMap();
        result.put("list", list);
        result.put("totalCount", totalCount);
        return result;
    }
}
package com.demo.servlet;

import com.demo.util.Util;
import com.demo.service.NoticeService;
    }
script>
html>
<%@ page contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>迁出编辑title>
    <%@ include file="include/head.jsp" %>
head>
<body>
<div class="container-fluid">
    <ul class="nav nav-tabs">
        <li><a href="OutmigrationServlet?action=list">迁出列表a>li>
        <li class="active"><a href="#">编辑a>li>
    ul>
    <br/>
    <form class="form-horizontal" role="form" action="OutmigrationServlet?action=edit" method="post" onsubmit="return check()">
        <input type="hidden" class="form-control" id="id" name="id" value="${vo.id}"/>
<div class="container-fluid">
    <ul class="nav nav-tabs">
        <li><a href="OutmigrationServlet?action=list">迁出列表a>li>
        <li class="active"><a href="#">添加a>li>
    ul>
    <br/>
    <form class="form-horizontal" role="form" action="OutmigrationServlet?action=add" method="post" onsubmit="return check()">
        <div class="form-group">
            <label class="col-sm-3 control-label">姓名:label>
            <div class="col-sm-5">
                <input type="text" class="form-control" id="outmigrationName" name="outmigrationName">
/**
 * User模块的Servlet控制层,负责接收页面传过来的请求参数,根据action参数的值来确定页面要执行的具体操作
* 而后再调用UserService业务层的方法来处理具体的业务,最后将处理完成的结果返回或跳转至相应页面 */
//@WebServlet("/UserServlet") public class UserServlet extends HttpServlet { /** * 处理Post请求 * * @param request * @param response * @throws ServletException * @throws IOException */ @Override
            ps.execute();
            ps.close();
            c.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    //@Override
    public boolean delete(long id) {
        try {
            Connection c = Util.getConnection();
            Statement s = c.createStatement();
            String sql = "delete from `t_household` where id = " + id;
            s.execute(sql);
            s.close();
            c.close();
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return vo;
    }

    //@Override
    public Map<String, Object> list(Map<String, Object> params) {
        List<Household> list = new ArrayList();
        int totalCount = 0;
        String condition = "";
        String sqlList;
        if (params.get("searchColumn") != null && !"".equals(params.get("searchColumn"))) {
            condition += " and `" + params.get("searchColumn") + "` like '%" + params.get("keyword") + "%'";
        }
        try {
            Connection c = Util.getConnection();
<body>
<div class="container-fluid">
    <ul class="nav nav-tabs">
        <li><a href="HouseholdServlet?action=list">户籍列表a>li>
        <li class="active"><a href="#">编辑a>li>
    ul>
    <br/>
    <form class="form-horizontal" role="form" action="HouseholdServlet?action=edit" method="post" onsubmit="return check()">
        <input type="hidden" class="form-control" id="id" name="id" value="${vo.id}"/>
        
            <div class="form-group">
                <label class="col-sm-3 control-label">姓名:label>
                <div class="col-sm-5">
                    <input type="text" class="form-control" id="householdName" name="householdName" value="${vo.householdName}">
                div>
            div>
        <div class="form-group">
            <label class="col-sm-3 control-label">性别:label>
            <div class="col-sm-5">
                              
                              
            div>
        <li><a href="HouseholdServlet?action=list">户籍列表a>li>
        <li class="active"><a href="#">添加a>li>
    ul>
    <br/>
    <form class="form-horizontal" role="form" action="HouseholdServlet?action=add" method="post" onsubmit="return check()">
        <div class="form-group">
            <label class="col-sm-3 control-label">姓名:label>
            <div class="col-sm-5">
                <input type="text" class="form-control" id="householdName" name="householdName">
            div>
        div>
        <div class="form-group">
            <label class="col-sm-3 control-label">性别:label>
            <div class="col-sm-5">
                <input name="householdSex" type="radio" value="" checked="checked"/>       
                <input name="householdSex" type="radio" value=""/>       
            div>
    //@Override
    public void update(User vo) {
        String sql = "update `t_user` set `username` = ? ,`password` = ? ,`real_name` = ? ,`user_sex` = ? ,`user_phone` = ? ,`user_text` = ? ,`user_type` = ?  where `id` = ?";
        try {
            Connection c = Util.getConnection();
            PreparedStatement ps = c.prepareStatement(sql);
            
            ps.setString(1, vo.getUsername());
            ps.setString(2, vo.getPassword());
            ps.setString(3, vo.getRealName());
            ps.setString(4, vo.getUserSex());
            ps.setString(5, vo.getUserPhone());
            ps.setString(6, vo.getUserText());
            vo.setUserSex(Util.decode(request, "userSex"));
            vo.setUserPhone(Util.decode(request, "userPhone"));
            vo.setUserText(Util.decode(request, "userText"));
            vo.setUserType(Util.decode(request, "userType"));
            UserService userService = new UserServiceImpl();
            //调用Service层更新方法(update),更新记录
            userService.update(vo);
            this.redirectList(request, response);
        } else if ("get".equalsIgnoreCase(action) || "editPre".equalsIgnoreCase(action)) {//根据主键ID,查询详情信息并跳转到详情页面或编辑页面
            Serializable id = Util.decode(request, "id");//取出页面传入的主键,用于查询详情
            UserService userService = new UserServiceImpl();
            User vo = userService.get(id);
            request.getSession().setAttribute("vo", vo);
            String to = "get".equalsIgnoreCase(action) ? "info" : "edit";//判断是去详情显示页面还是编辑页面
            response.sendRedirect("user_" + to + ".jsp");
        } else {//默认去列表页面
            this.redirectList(request, response);
        }
    }

            <label class="col-sm-3 control-label">备注:label>
            <div class="col-sm-5">
                <textarea rows="3" class="form-control" id="immigrationText" name="immigrationText" placeholder="请输入内容......">${vo.immigrationText}textarea>
            div>
        div>
        <div class="form-group">
            <label class="col-sm-3 control-label">label>
            <div class="col-sm-5">
                <input type="submit" class="btn btn-line btn-warning btn-sm" value="保存">
                <input type="button" class="btn btn-line btn-default btn-sm" value="返回" onclick="javascript:history.back(-1);">
            div>
        HouseholdService householdService = new HouseholdServiceImpl();
        Map<String, Object> map = householdService.list(params);
        request.getSession().setAttribute("list", map.get("list"));

        Integer totalRecord = (Integer) map.get("totalCount");//根据查询条件取出对应的总记录数,用于分页
        String pageNum = Util.decode(request, "pageNum");//封装分页参数
        com.demo.util.PageBean<Object> pb = new com.demo.util.PageBean(Integer.valueOf(pageNum != null ? pageNum : "1"), totalRecord);
        params.put("startIndex", pb.getStartIndex());
        params.put("pageSize", pb.getPageSize());
        List list = (List) householdService.list(params).get("list");//根据分页参数startIndex、pageSize查询出来的最终结果list
        pb.setServlet("HouseholdServlet");
            PreparedStatement ps = c.prepareStatement(sql);
            
            ps.setString(1, vo.getUsername());
            ps.setString(2, vo.getPassword());
            ps.setString(3, vo.getRealName());
            ps.setString(4, vo.getUserSex());
            ps.setString(5, vo.getUserPhone());
            ps.setString(6, vo.getUserText());
            ps.setString(7, vo.getUserType());
            ps.execute();
            ps.close();
            c.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    //@Override
    public void update(User vo) {
        String sql = "update `t_user` set `username` = ? ,`password` = ? ,`real_name` = ? ,`user_sex` = ? ,`user_phone` = ? ,`user_text` = ? ,`user_type` = ?  where `id` = ?";
                <input type="text" class="form-control" id="outmigrationHandler" name="outmigrationHandler">
            div>
        div>
        <div class="form-group">
            <label class="col-sm-3 control-label">迁出时间:label>
            <div class="col-sm-5">
                <input type="text" class="form-control" id="outmigrationTime" name="outmigrationTime">
            div>
        div>
        <div class="form-group">
            <label class="col-sm-3 control-label">备注:label>
            <div class="col-sm-5">
                <textarea rows="3" class="form-control" id="immigrationText" name="immigrationText" placeholder="请输入内容......">textarea>
        if (document.getElementById("householdArea").value.trim().length == 0) {
            alert("所在区不能为空!");
            return false;
        }
        if (document.getElementById("householdHouseno").value.trim().length == 0) {
            alert("房屋号不能为空!");
            return false;
        }
        if (document.getElementById("householdUnit").value.trim().length == 0) {
            alert("单元不能为空!");
            return false;
        }
        if (document.getElementById("householdStyle").value.trim().length == 0) {
            alert("户型不能为空!");
            return false;
        }
        return true;
    }
script>
html>
<%@ page contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<html>
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    @Override
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //过滤编码
        request.setCharacterEncoding("UTF-8");
        response.setCharacterEncoding("UTF-8");
        String action = Util.decode(request, "action");
        if ("add".equals(action)) {//增加
            Outmigration vo = new Outmigration();
            //取出页面传进来的各个数据,并设置到Outmigration对象的属性里
            vo.setOutmigrationName(Util.decode(request, "outmigrationName"));
            vo.setOutmigrationSex(Util.decode(request, "outmigrationSex"));
    <ul class="nav nav-tabs">
        <li><a href="HouseholdServlet?action=list">户籍列表a>li>
        <li class="active"><a href="#">编辑a>li>
    ul>
    <br/>
    <form class="form-horizontal" role="form" action="HouseholdServlet?action=edit" method="post" onsubmit="return check()">
        <input type="hidden" class="form-control" id="id" name="id" value="${vo.id}"/>
        
            <div class="form-group">
                <label class="col-sm-3 control-label">姓名:label>
                <div class="col-sm-5">
                    <input type="text" class="form-control" id="householdName" name="householdName" value="${vo.householdName}">
                div>
            div>
        <div class="form-group">
            <label class="col-sm-3 control-label">性别:label>
            <div class="col-sm-5">
                              
                              
            div>
import java.util.List;
import java.util.Map;

/**
 * Outmigration模块的Servlet控制层,负责接收页面传过来的请求参数,根据action参数的值来确定页面要执行的具体操作
* 而后再调用OutmigrationService业务层的方法来处理具体的业务,最后将处理完成的结果返回或跳转至相应页面 */
//@WebServlet("/OutmigrationServlet") public class OutmigrationServlet extends HttpServlet { /** * 处理Post请求 * * @param request * @param response * @throws ServletException * @throws IOException */ @Override public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //过滤编码 request.setCharacterEncoding("UTF-8");
        response.sendRedirect("notice_list.jsp");
    }
}
package com.demo.dao.impl;

import com.demo.util.Util;
import com.demo.dao.UserDAO;
import com.demo.vo.User;

import java.io.Serializable;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * User模块的DAO层(数据层)的具体实现类,对UserDAO接口中定义的增删改查等抽象方法作出具体的功能实现
 */
public class UserDAOImpl implements UserDAO {

                vo.setOutmigrationPayway(rs.getString("outmigration_payway"));
                vo.setOutmigrationHandler(rs.getString("outmigration_handler"));
                vo.setOutmigrationTime(rs.getString("outmigration_time"));
                vo.setImmigrationText(rs.getString("immigration_text"));
            }
            c.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return vo;
    }

    //@Override
    public Map<String, Object> list(Map<String, Object> params) {
        List<Outmigration> list = new ArrayList();
        int totalCount = 0;
        String condition = "";
        String sqlList;
        if (params.get("searchColumn") != null && !"".equals(params.get("searchColumn"))) {
            condition += " and `" + params.get("searchColumn") + "` like '%" + params.get("keyword") + "%'";
import java.io.Serializable;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

                msg = "原密码错误!";
            } else {
                String newPassword = Util.decode(request, "newPassword");
                loginUser.setPassword(newPassword);
                UserService userService = new UserServiceImpl();
                userService.update(loginUser);
                msg = "修改成功!";
            }
            request.getSession().setAttribute("alert_msg", msg);
            request.getRequestDispatcher("reset_password.jsp").forward(request, response);
            //取出页面传进来的各个数据,并设置到User对象的属性里
            User vo = new User();
            vo.setId(Long.valueOf(Util.decode(request, "id")));
            vo.setUsername(Util.decode(request, "username"));
            vo.setPassword(Util.decode(request, "password"));
            vo.setRealName(Util.decode(request, "realName"));
            vo.setUserSex(Util.decode(request, "userSex"));
            vo.setUserPhone(Util.decode(request, "userPhone"));
            vo.setUserText(Util.decode(request, "userText"));
            vo.setUserType(Util.decode(request, "userType"));
            UserService userService = new UserServiceImpl();
            //调用Service层更新方法(update),更新记录
            userService.update(vo);
            this.redirectList(request, response);
        } else if ("get".equalsIgnoreCase(action) || "editPre".equalsIgnoreCase(action)) {//根据主键ID,查询详情信息并跳转到详情页面或编辑页面
            Serializable id = Util.decode(request, "id");//取出页面传入的主键,用于查询详情
            UserService userService = new UserServiceImpl();
            User vo = userService.get(id);
            request.getSession().setAttribute("vo", vo);
            String to = "get".equalsIgnoreCase(action) ? "info" : "edit";//判断是去详情显示页面还是编辑页面
            response.sendRedirect("user_" + to + ".jsp");
        } else {//默认去列表页面
            this.redirectList(request, response);
        }
        Map<String, Object> result = new HashMap();
        result.put("list", list);
        result.put("totalCount", totalCount);
        return result;
    }
}
<%@ page contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>户籍编辑title>
    <%@ include file="include/head.jsp" %>
head>
<body>
<div class="container-fluid">
    <ul class="nav nav-tabs">
        <li><a href="HouseholdServlet?action=list">户籍列表a>li>
            String sqlCount = "select count(*) from `t_user` where 1=1 " + condition;
            ps = c.prepareStatement(sqlCount);
            rs = ps.executeQuery();
            if (rs.next()) {
                totalCount = rs.getInt(1);
            }
            rs.close();
            ps.close();
            c.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        Map<String, Object> result = new HashMap();
        result.put("list", list);
        result.put("totalCount", totalCount);
        return result;
    }

运行环境

Java≥6、Tomcat≥7.0、MySQL≥5.5

开发工具

eclipse/idea/myeclipse/sts等均可配置运行

技术框架

JavaWeb JavaBean JSP MVC MySQL Tomcat JavaScript Bootstrap

基础JSP+Servlet或JSP+SSM(Spring、SpringMVC、MyBatis)框架或JSP+SSM+Maven(pom.xml)框架或SpringBoot…均可

适用

课程设计,大作业,毕业设计,项目练习,学习演示等

功能说明

登录、注册、退出、用户模块、公告模块、户籍模块、反馈模块、迁入模块、迁出模块的增删改查管理

基于javaweb+jsp的户籍管理系统_第1张图片

基于javaweb+jsp的户籍管理系统_第2张图片

基于javaweb+jsp的户籍管理系统_第3张图片

基于javaweb+jsp的户籍管理系统_第4张图片

基于javaweb+jsp的户籍管理系统_第5张图片

基于javaweb+jsp的户籍管理系统_第6张图片

基于javaweb+jsp的户籍管理系统_第7张图片

基于javaweb+jsp的户籍管理系统_第8张图片

基于javaweb+jsp的户籍管理系统_第9张图片

基于javaweb+jsp的户籍管理系统_第10张图片

基于javaweb+jsp的户籍管理系统_第11张图片

基于javaweb+jsp的户籍管理系统_第12张图片

基于javaweb+jsp的户籍管理系统_第13张图片

基于javaweb+jsp的户籍管理系统_第14张图片

↖[获取源码方式]见左侧

你可能感兴趣的:(java-ee,java,mysql,tomcat)