第七次全國人口普查登記(20分)
1、項目需求:
開展第七次全國人口普查,將為編制“十四五”規划提供重要信息支持;推動實現人口與經濟社會、資源環境協調發展,為深化供給側結構性改革,推動經濟高質量發展,建設現代化經濟體系提供強有力的支持;人口普查還將為完善人口發展戰略和政策體系,促進人口長期均衡發展提供重要信息支持。
2.系統要求與功能設計
2.1 頁面功能要求
(1)能夠在Tomcat服務器中正確部署,並通過瀏覽器查看;(1分)
(2)網站頁面整體風格統一;
圖1 人口普查系統功能結構圖
(3)主頁面:要求顯示人口登記、修改人口信息、刪除人口信息、查詢人口信息,人口信息瀏覽五個子菜單。(1分)
(4)人口登記頁面:(6分)
①完成添加人口信息登記,基本信息和填報限制如下表所示
戶 別 |
家庭戶 集體戶(單選框) |
住房類型 |
家庭住宅、集體住所、工作地住所、其他住宅、無住宅(單選框) |
本戶現住房面積 |
XXXXX平方米(文本框,只能輸入這個整數) |
本戶現住房間數 |
XXXXX間(文本框,只能輸入這個整數) |
戶主姓名 |
XXXXX(文本框) |
身份證號碼 |
XXXXXXXXXXXXXXXXXX(判斷身份證位數13位並且只能錄入數字、最后一位可以錄入X) |
性別 |
男/女(單選框) |
民族 |
(文本框) |
受教育程度 |
研究生、大學本科、大學專科、高中、初中、小學、未上過學(下拉框實現) |
②點擊“提交”按鈕,保存成功則跳轉到人口基本信息瀏覽界面,新錄入的信息置頂顯示。失敗則提示錯誤信息,返回當前頁面
評分標准:
①完成人口登記頁面(未完成0分,完成1分)
②保存人口信息入庫(未完成0分,完成1分)
③戶別、住房類別、性別實現一個單選框錄入0.5分,全部實現1分。(未完成0分,完成一個0.5,全部完成1分)
④本戶現住房面積或本戶現住房間數實現整數判斷(未完成0分,完成0.5分)
⑤判斷身份證按照要求錄入,實現位數和數字錄入判斷0.5分,實現最后一位可以輸入數字或X判斷0.5分。(1分)
⑥受教育程度下拉框錄入(未完成0分,完成0.5分)
⑦提交后頁面跳轉功能;(未完成0分,完成1分)
(5)修改人口信息頁面:(3分)
輸入戶主姓名,顯示其余信息,可對身份證號碼、性別、民族、受教育程度進行修改。(身份證號碼、性別、受教育程度必須符合錄入要求);如果該名戶主信息數據庫不存在,則提示“該戶主信息不存在”。(3分)
評分標准:
①完成修改戶主個人信息頁面(未完成0分,完成0.5分)
② 實現數據庫中信息更新(未完成0分,完成1分)
③修改信息判斷是否符合要求。(未完成0分,完成0.5分)
④輸入姓名,顯示其余信息,若該信息不存在,提示錯誤信息;(未完成0分,完成1分)
(6)刪除人口信息頁面:錄入戶主姓名,顯示詳細信息后,點擊“刪除”按鈕,彈出提示框,提示“是否確認刪除該戶主信息”,確認后刪除該信息。(1分)
評分標准:
①輸入戶主姓名可顯示其余信息。(未完成0分,完成0.5分)
②對應刪除數據庫中信息(未完成0分,完成0.5分)
(7)瀏覽人口信息頁面:(2分)
以列表形式顯示人口基本信息,結果列表中顯示姓名、性別,民族、受教育程度基本信息,點擊姓名,可以跳轉到個人詳細信息。
①實現以列表形式顯示人口基本信息,結果列表中顯示姓名、性別,民族、受教育程度基本信息(未完成0分,完成1分)
②實現跳轉個人詳細信息頁面。(未完成0分,完成1分)
(8)查詢人口信息頁面:(3分)
要求可以根據人口姓名、性別、民族、受教育程度四種條件實現模糊查詢,輸出結果以列表形式顯示,顯示人口姓名、性別、民族、受教育程度基本信息,點擊列表中的姓名,跳轉到人口個人詳細信息頁面。
評分標准:
①缺少一種查詢條件扣除1分。(未完成0分,完成3分)
2.2 功能要求
(1)設計出合理的數據庫和數據表,要求使用mysql、sqlserver、oracle三種數據庫中一種(1分)
(2)使用Serverlet實現頁面交互(1分)。
(3)使用Java Bean封裝數據庫連接操作(1分。)
\
DAO部分
package Dao;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import people.people;
import util.DBUtil;
/**
* 課程Dao
* Dao層操作數據
* @author Hu
*
*/
public class Dao {
/**
* 添加
* @param course
* @return
*/
public boolean add(people people) {
String sql = "insert into zhufang(name,idc,sex,min_zu,jiao_yu,hu_bie,zhu_fang_lei_bie,S,N) values('" + people.getName() + "','" + people.getIdc() + "','" + people.getSex() + "','" + people.getMin_zu() + "','" + people.getJiao_yu() + "','" + people.getHu_bie() + "','" + people.getZhu_fang_lei_bie() + "','" + people.getS() + "','" + people.getN() + "')";
//創建數據庫鏈接
Connection conn = DBUtil.getConn();
Statement state = null;
boolean f = false;
int a = 0;
try {
state = conn.createStatement();
a = state.executeUpdate(sql);
} catch (Exception e) {
e.printStackTrace();
} finally {
//關閉連接
DBUtil.close(state, conn);
}
if (a > 0) {
f = true;
}
return f;
}
/**
* 刪除
*
* @param id
* @return
*/
public boolean delete (int id) {
boolean f = false;
String sql = "delete from zhufang where id='" + id + "'";
Connection conn = DBUtil.getConn();
Statement state = null;
int a = 0;
try {
state = conn.createStatement();
a = state.executeUpdate(sql);
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(state, conn);
}
if (a > 0) {
f = true;
}
return f;
}
/**
* 修改
* @param name
* @param pass
*/
/**
* @param people
* @return
*/
public boolean update(people people) {
String sql = "update zhufang set name='" + people.getName() + "', idc='" + people.getIdc() + "', sex='" + people.getSex() + "', min_zu='" + people.getMin_zu() + "', jiao_yu='" + people.getJiao_yu()
+ "' where id='" + people.getId() + "'";
Connection conn = DBUtil.getConn();
Statement state = null;
boolean f = false;
int a = 0;
try {
state = conn.createStatement();
a = state.executeUpdate(sql);
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(state, conn);
}
if (a > 0) {
f = true;
}
return f;
}
/**
* 驗證課程名稱是否唯一
* true --- 不唯一
* @param name
* @return
*/
public boolean leibie(String name) {
boolean flag = false;
String sql = "select name from zhufang where name = '" + name + "'";
Connection conn = DBUtil.getConn();
Statement state = null;
ResultSet rs = null;
try {
state = conn.createStatement();
rs = state.executeQuery(sql);
while (rs.next()) {
flag = true;
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(rs, state, conn);
}
return flag;
}
/**
* 通過ID得到課程信息
* @param id
* @return
*/
public people getById(int id) {
String sql = "select * from zhufang where id ='" + id + "'";
Connection conn = DBUtil.getConn();
Statement state = null;
ResultSet rs = null;
people people = null;
try {
state = conn.createStatement();
rs = state.executeQuery(sql);
while (rs.next()) {
String name = rs.getString("name");
String min_zu = rs.getString("min_zu");
String jiao_yu = rs.getString("jiao_yu");
String idc = rs.getString("idc");
String sex = rs.getString("sex");
int ida = rs.getInt("id");
people = new people(ida,name,idc,min_zu,jiao_yu,sex);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
DBUtil.close(rs, state, conn);
}
return people;
}
/**
* 通過name得到Course
* @param name
* @return
*/
public people getByName(String name) {
String sql = "select * from zhufang where name ='" + name + "'";
Connection conn = DBUtil.getConn();
Statement state = null;
ResultSet rs = null;
people people = null;
try {
state = conn.createStatement();
rs = state.executeQuery(sql);
while (rs.next()) {
int id = rs.getInt("id");
String name1 = rs.getString("name");
String zhu_fang_lei_bie = rs.getString("zhu_fang_lei_bie");
String hu_bie = rs.getString("hu_bie");
String idc = rs.getString("idc");
String jiao_yu = rs.getString("jiao_yu");
String min_zu = rs.getString("min_zu");
int S = rs.getInt("S");
int N = rs.getInt("N");
String sex = rs.getString("sex");
people = new people(id,hu_bie,zhu_fang_lei_bie,name1,idc,min_zu,jiao_yu,sex,S,N);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
DBUtil.close(rs, state, conn);
}
return people;
}
/**
* 查找
* @param name
* @param teacher
* @param classroom
* @return
*/
public List<people> search(String name,String sex, String min_zu, String jiao_yu) {
String sql = "select * from zhufang where ";
if (name != "") {
sql += "name like '%" + name + "%'";
}
else if (min_zu != "") {
sql += "min_zu like '%" + min_zu + "%'";
}
else if (jiao_yu != "") {
sql += "jiao_yu like '%" + jiao_yu + "%'";
}
else if (sex != "") {
sql += "sex like '%" + sex + "%'";
}
else
{
}
List<people> list = new ArrayList<>();
Connection conn = DBUtil.getConn();
Statement state = null;
ResultSet rs = null;
try {
state = conn.createStatement();
rs = state.executeQuery(sql);
people bean = null;
while (rs.next()) {
int id = rs.getInt("id");
String name2 = rs.getString("name");
String min_zu2 = rs.getString("min_zu");
String jiao_yu2 = rs.getString("jiao_yu");
String sex2 = rs.getString("sex");
String idc2 = rs.getString("idc");
bean = new people(id,name2,idc2,min_zu2,jiao_yu2,sex2);
list.add(bean);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(rs, state, conn);
}
return list;
}
/**
* 全部數據
* @param name
* @param teacher
* @param classroom
* @return
*/
public List<people> list() {
String sql = "select * from zhufang";
List<people> list = new ArrayList<>();
Connection conn = DBUtil.getConn();
Statement state = null;
ResultSet rs = null;
try {
state = conn.createStatement();
rs = state.executeQuery(sql);
people bean = null;
while (rs.next()) {
int id = Integer.parseInt(rs.getString("id"));
String name2 = rs.getString("name");
String min_zu2 = rs.getString("min_zu");
String jiao_yu2 = rs.getString("jiao_yu");
String sex2 = rs.getString("sex");
String idc2 = rs.getString("idc");
String hu_bie2 = rs.getString("hu_bie");
String zhu_fang_lei_bie2 = rs.getString("zhu_fang_lei_bie");
int S2 = Integer.parseInt(rs.getString("S"));
int N2 = Integer.parseInt(rs.getString("N"));
bean = new people(id,hu_bie2,zhu_fang_lei_bie2,name2,idc2,min_zu2,jiao_yu2,sex2,S2,N2);
list.add(bean);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(rs, state, conn);
}
return list;
}
}
Servlet部分
package Servlet;
import java.io.IOException;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import people.people;
import Service.Service;
@WebServlet("/Servlet")
public class Servlet extends HttpServlet {
private static final long serialVersionUID = 1L;
Service service = new Service();
/**
* 方法選擇
*/
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setCharacterEncoding("utf-8");
String method = req.getParameter("method");
if ("add".equals(method)) {
add(req, resp);
} else if ("del".equals(method)) {
del(req, resp);
} else if ("update".equals(method)) {
update(req, resp);
} else if ("search".equals(method)) {
search(req, resp);
} else if ("getbyid".equals(method)) {
getById(req, resp);
} else if ("getbyname".equals(method)) {
getByName(req, resp);
} else if ("list".equals(method)) {
list(req, resp);
}
}
/**
* 添加
* @param req
* @param resp
* @throws IOException
* @throws ServletException
*/
private void add(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
req.setCharacterEncoding("utf-8");
//獲取數據
String hu_bie = req.getParameter("hu_bie");
String zhu_fang_lei_bie = req.getParameter("zhu_fang_lei_bie");
String name = req.getParameter("name");
String idc = req.getParameter("idc");
String min_zu = req.getParameter("min_zu");
String jiao_yu = req.getParameter("jiao_yu");
String sex = req.getParameter("sex");
int S = Integer.parseInt(req.getParameter("S"));
int N = Integer.parseInt(req.getParameter("N"));
people people = new people(hu_bie,zhu_fang_lei_bie,name,idc,min_zu,jiao_yu,sex,S,N);
//添加后消息顯示
if(service.add(people)) {
req.setAttribute("message", "添加成功");
req.getRequestDispatcher("add.jsp").forward(req,resp);
} else {
req.setAttribute("message", "添加失敗,請重新錄入");
req.getRequestDispatcher("add.jsp").forward(req,resp);
}
}
/**
* 全部
* @param req
* @param resp
* @throws ServletException
*/
private void list(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{
req.setCharacterEncoding("utf-8");
List<people> peoples = service.list();
req.setAttribute("peoples", peoples);
req.getRequestDispatcher("detail2.jsp").forward(req,resp);
}
/**
* 通過ID得到Course
* @param req
* @param resp
* @throws ServletException
*/
private void getById(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{
req.setCharacterEncoding("utf-8");
int id = Integer.parseInt(req.getParameter("id"));
people people = service.getById(id);
req.setAttribute("people", people);
req.getRequestDispatcher("detail2.jsp").forward(req,resp);
}
/**
* 通過名字查找
* 跳轉至刪除
* @param req
* @param resp
* @throws IOException
* @throws ServletException
*/
private void getByName(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{
req.setCharacterEncoding("utf-8");
String name = req.getParameter("name");
people people =service.getByName(name);
if(people == null) {
req.setAttribute("message", "查無此人!");
req.getRequestDispatcher("del.jsp").forward(req,resp);
} else {
req.setAttribute("people", people);
req.getRequestDispatcher("detail.jsp").forward(req,resp);
}
}
/**
* 刪除
* @param req
* @param resp
* @throws IOException
* @throws ServletException
*/
private void del(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{
req.setCharacterEncoding("utf-8");
int id = Integer.parseInt(req.getParameter("id"));
service.del(id);
req.setAttribute("message", "刪除成功!");
req.getRequestDispatcher("del.jsp").forward(req,resp);
}
/**
* 修改
* @param req
* @param resp
* @throws IOException
* @throws ServletException
*/
private void update(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{
req.setCharacterEncoding("utf-8");
int id = Integer.parseInt(req.getParameter("id"));
String name = req.getParameter("name");
String idc = req.getParameter("idc");
String min_zu = req.getParameter("min_zu");
String jiao_yu = req.getParameter("jiao_yu");
String sex1 = req.getParameter("sex");
people people = new people(id,name,idc,min_zu,jiao_yu,sex1);
service.update(people);
req.setAttribute("message", "修改成功");
req.getRequestDispatcher("Servlet?method=list").forward(req,resp);
}
/**
* 查找
* @param req
* @param resp
* @throws ServletException
*/
private void search(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{
req.setCharacterEncoding("utf-8");
String name = req.getParameter("name");
String min_zu = req.getParameter("min_zu");
String jiao_yu = req.getParameter("jiao_yu");
String sex = req.getParameter("sex");
List<people> peoples = service.search(name,sex,min_zu,jiao_yu);
req.setAttribute("peoples", peoples);
req.getRequestDispatcher("list.jsp").forward(req,resp);
}
}
服務層部分
package Service;
import java.util.List;
import Dao.Dao;
import people.people;
/**
* Service
* 服務層
* @author Hu
*
*/
public class Service {
Dao cDao = new Dao();
/**
* 添加
* @param course
* @return
*/
public boolean add(people people) {
boolean f = false;
if(!cDao.leibie(people.getName())) {
cDao.add(people);
f = true;
}
return f;
}
/**
* 刪除
*/
public void del(int id) {
cDao.delete(id);
}
/**
* 修改
* @return
*/
public void update(people people) {
cDao.update(people);
}
/**
* 通過ID得到一個Course
* @return
*/
public people getById(int id) {
return cDao.getById(id);
}
/**
* 通過Name得到一個Course
* @return
*/
public people getByName(String name) {
return cDao.getByName(name);
}
/**
* 查找
* @return
*/
public List<people> search(String name, String sex, String min_zu,String jiao_yu) {
return cDao.search(name,sex,min_zu,jiao_yu);
}
/**
* 全部數據
* @return
*/
public List<people> list() {
return cDao.list();
}
}
類的封裝部分
package people;
public class people {
String hu_bie;
String zhu_fang_lei_bie;
int S;
int N;
String name;
String idc;
String sex;
String min_zu;
String jiao_yu;
int id;
public people(int id,String name, String idc, String min_zu, String jiao_yu)
{
this.id = id;
this.min_zu = min_zu;
this.jiao_yu = jiao_yu;
this.name = name;
this.idc = idc;
}
public people(int id,String name, String idc, String min_zu, String jiao_yu,String sex) {
this.id = id;
this.sex = sex;
this.min_zu = min_zu;
this.jiao_yu = jiao_yu;
this.name = name;
this.idc = idc;
}
public people(String hu_bie, String zhu_fang_lei_bie, String name, String idc, String min_zu, String jiao_yu,String sex,int S,int N) {
this.hu_bie = hu_bie;
this.zhu_fang_lei_bie = zhu_fang_lei_bie;
this.S = S;
this.N = N;
this.sex = sex;
this.min_zu = min_zu;
this.jiao_yu = jiao_yu;
this.name = name;
this.idc = idc;
}
public people(int id,String hu_bie, String zhu_fang_lei_bie, String name, String idc, String min_zu, String jiao_yu,String sex,int S,int N) {
this.id = id;
this.hu_bie = hu_bie;
this.zhu_fang_lei_bie = zhu_fang_lei_bie;
this.S = S;
this.N = N;
this.sex = sex;
this.min_zu = min_zu;
this.jiao_yu = jiao_yu;
this.name = name;
this.idc = idc;
}
public String getHu_bie() {
return hu_bie;
}
public void setHu_bie(String hu_bie) {
this.hu_bie = hu_bie;
}
public String getZhu_fang_lei_bie() {
return zhu_fang_lei_bie;
}
public void setZhu_fang_lei_bie(String zhu_fang_lei_bie) {
this.zhu_fang_lei_bie = zhu_fang_lei_bie;
}
public int getS() {
return S;
}
public void setS(int s) {
S = s;
}
public int getN() {
return N;
}
public void setN(int n) {
N = n;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getIdc() {
return idc;
}
public void setIdc(String idc) {
this.idc = idc;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public String getMin_zu() {
return min_zu;
}
public void setMin_zu(String min_zu) {
this.min_zu = min_zu;
}
public String getJiao_yu() {
return jiao_yu;
}
public void setJiao_yu(String jiao_yu) {
this.jiao_yu = jiao_yu;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
}
數據庫連接
package util;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class DBUtil {
public static String db_url = "jdbc:mysql://localhost:3306/pu_cha?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone = GMT&allowPublicKeyRetrieval=true";
public static String db_user = "root";
public static String db_pass = "root";
public static Connection getConn () {
Connection conn = null;
try {
Class.forName("com.mysql.cj.jdbc.Driver");//加載驅動
conn = DriverManager.getConnection(db_url, db_user, db_pass);
} catch (Exception e) {
e.printStackTrace();
}
return conn;
}
/*10鍏抽棴榪炴帴*/
public static void close (Statement state, Connection conn) {
if (state != null) {
try {
state.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (conn != null) {
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
public static void close (ResultSet rs, Statement state, Connection conn) {
if (rs != null) {
try {
rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (state != null) {
try {
state.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (conn != null) {
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
public static void main(String[] args) throws SQLException {
}
}
主菜單
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>人口普查系統</title>
</head>
<body>
<div align="center">
<div class="a">
<a href="add.jsp">信息登記</a>
</div>
<div class="a">
<a href="Servlet?method=list">信息修改</a>
</div>
<div class="a">
<a href="del.jsp">信息刪除</a>
</div>
<div class="a">
<a href="searchlist.jsp">信息查詢</a>
</div>
</div>
</body>
</html>
添加信息
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>人口信息登記</title>
</head>
<body>
<%
Object message = request.getAttribute("message");
if(message!=null && !"".equals(message)){
%>
<script type="text/javascript">
alert("<%=request.getAttribute("message")%>");
</script>
<%} %>
<div align="center">
<h1 style="color: black;">人口信息登記</h1>
<a href="menu.jsp">返回主頁</a>
<form name="form1" action="Servlet?method=add" method="post" onsubmit="return check()">
<div class="a">
戶 別
集體戶<input type="radio" id="hu_bie" name="hu_bie" value="collectivehousehold" >
家庭戶<input type="radio" id="hu_bie" name="hu_bie" value="households" >
</div>
<div class="a">
住房類型
家庭住宅<input type="radio" id="zhu_fang_lei_bie" name="zhu_fang_lei_bie" value="familyhome" >
集體住所<input type="radio" id="zhu_fang_lei_bie" name="zhu_fang_lei_bie" value="collectivehouseing" >
工作地住所<input type="radio" id="zhu_fang_lei_bie" name="zhu_fang_lei_bie" value="workplacehousing" >
其他住宅<input type="radio" id="zhu_fang_lei_bie" name="zhu_fang_lei_bie" value="otherresidential" >
無住宅<input type="radio" id="zhu_fang_lei_bie" name="zhu_fang_lei_bie" value="noresidence" >
</div>
<div class="a">
現住房面積<input type="text" id="S" name="S" />
</div>
<div class="a">
現住房房間數<input type="text" id="N" name="N" />
</div>
<div class="a">
戶主姓名<input type="text" id="name" name="name" />
</div>
<div class="a">
身份證號碼<input type="text" id="idc" name="idc" />
</div>
<div class="a">
性別
男<input type="radio" name="sex" value="nan" >
女<input type="radio" name="sex" value="nv" >
</div>
<div class="a">
民族<input type="text" id="min_zu" name="min_zu" />
</div>
<div class="a">
受教育程度
研究生<input type="radio" id="jiao_yu" name="jiao_yu" value="postgraduate" >
大學本科<input type="radio" id="jiao_yu" name="jiao_yu" value="undergraduate" >
大學專科<input type="radio" id="jiao_yu" name="jiao_yu" value="college" >
高中<input type="radio" id="jiao_yu" name="jiao_yu" value="highschool" >
初中<input type="radio" id="jiao_yu" name="jiao_yu" value="juniorhighschool" >
小學<input type="radio" id="jiao_yu" name="jiao_yu" value="primaryschool" >
未上過學<input type="radio" id="jiao_yu" name="jiao_yu" value="uneducated" >
</div>
<div class="a">
<button type="submit" class="b">保 存</button>
</div>
</form>
</div>
<script type="text/javascript">
function check() {
var S = document.form1.S.value;
var N = document.form1.N.value;
var idc = document.form1.idc.value;
var name = document.form1.name.value;
var jiao_yu = document.form1.jiao_yu.value;
var min_zu = document.form1.min_zu.value;;
var idc = document.form1.idc.value;
//非空
if(jiao_yu == '') {
alert('受教育程度為空');
jiao_yu.focus();
return false;
}
if(min_zu == '') {
alert('民族為空');
min_zu.focus();
return false;
}
if(S == '') {
alert('住房面積為空');
S.focus();
return false;
}
if(N == '') {
alert('房間數為空');
N.focus();
return false;
}if(idc == '') {
alert('身份證號碼為空');
idc.focus();
return false;
}if(name == '') {
alert('戶主名為空');
name.focus();
return false;
}if(idc.length!=18)
{
alert('身份證號碼位數錯誤');
idc.focus();
return false;
}if(check_word(idc))
{
alert('身份證號碼包含字母');
idc.focus();
return false;
}
if ((document.theForm.S.value.indexOf("-") == 0)||!(document.theForm.S.value.indexOf(".") == -1)){
alert("住房面積不能為小數或負數");
document.theForm.S.focus();
return false;
}
if ((document.theForm.N.value.indexOf("-") == 0)||!(document.theForm.N.value.indexOf(".") == -1)){
alert("房間數不能為小數或負數");
document.theForm.N.focus();
return false;
}
}
function check_word(str)
{ var arr = ["a", "b", "c", "d", "e", "f", "g", "h","i","j", "k", "l", "m", "n", "o", "p", "q","r", "s", "t", "u", "v", "w", "x", "y","z","A", "B", "C", "D", "E", "F", "G", "H","I","J", "K", "L", "M", "N", "O", "P", "Q","R","S", "T", "U", "V", "W", "X", "Y", "Z"];
for (var i = 0; i < arr.length; i++)
{
for (var j = 0; j < str.length; j++)
{
if (arr[i] == str.charAt(j))
{
if(arr[i]=="X"&&j==18)
{
return false;
}
return true;
}
}
}
return false;
}
</script>
</body>
</html>
刪除信息
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>人口登記信息刪除</title>
</head>
<body>
<%
Object message = request.getAttribute("message");
if(message!=null && !"".equals(message)){
%>
<script type="text/javascript">
alert("<%=request.getAttribute("message")%>");
</script>
<%} %>
<div align="center">
<h1 style="color: black;">人口登記信息刪除</h1>
<a href="menu.jsp">返回主頁</a>
<form action="Servlet?method=getbyname" method="post" onsubmit="return check()">
<div class="a">
戶主性名<input type="text" id="name" name="name"/>
</div>
<div class="a">
<button type="submit" class="b">查 找</button>
</div>
</form>
</div>
<script type="text/javascript">
function check() {
var name = document.getElementById("name");;
//非空
if(name.value == '') {
alert('戶主名為空');
name.focus();
return false;
}
}
</script>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>人口登記信息刪除</title>
<style>
.a{
margin-top: 20px;
}
.b{
font-size: 20px;
width: 160px;
color: white;
background-color: greenyellow;
}
.tb, td {
border: 1px solid black;
font-size: 22px;
}
</style>
</head>
<body>
<div align="center">
<h1 style="color: black;">人口登記信息刪除</h1>
<a href="menu.jsp">返回主頁</a>
<table class="tb">
<tr>
<td>戶主姓名</td>
<td>${people.name}</td>
</tr>
<tr>
<td>身份證號碼</td>
<td>${people.idc}</td>
</tr>
<tr>
<td>性別</td>
<td>${people.sex}</td>
</tr>
<tr>
<td>民族</td>
<td>${people.min_zu}</td>
</tr>
<tr>
<td>受教育程度</td>
<td>${people.jiao_yu}</td>
</tr>
</table>
<div class="a">
<a onclick="return check()" href="Servlet?method=del&id=${people.id}">刪 除</a>
</div>
</div>
<script type="text/javascript">
function check() {
if (confirm("真的要刪除嗎?")){
return true;
}else{
return false;
}
}
</script>
</body>
</html>
遍歷輸出信息
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>信息列表</title>
</head>
<body>
<div align="center">
<h1 style="color: black;">信息列表</h1>
<a href="menu.jsp">返回主頁</a>
<table class="tb">
<tr>
<td>id</td>
<td>戶主</td>
<td>身份證號碼</td>
<td>性別</td>
<td>民族</td>
<td>受教育程度</td>
</tr>
<!-- forEach遍歷出adminBeans -->
<c:forEach items="${peoples}" var="item" varStatus="status">
<tr>
<td>${item.id}</td>
<td>${item.name}</td>
<td>${item.idc}</td>
<td>${item.sex}</td>
<td>${item.min_zu}</td>
<td>${item.jiao_yu}</td>
</tr>
</c:forEach>
</table>
</div>
</body>
</html>
查詢信息
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>人口登記信息查詢</title>
</head>
<body>
<div align="center">
<h1 style="color: black;">人口登記信息查詢</h1>
<a href="menu.jsp">返回主頁</a>
<form action="Servlet?method=search" method="post" onsubmit="return check()">
<div class="a">
戶主<input type="text" id="name" name="name"/>
</div>
<div class="a">
性別<input type="text" id="sex" name="sex" />
</div>
<div class="a">
民族<input type="text" id="min_zu" name="min_zu" />
</div>
<div class="a">
受教育程度<input type="text" id="jiao_yu" name="jiao_yu" />
</div>
<div class="a">
<button type="submit" class="b">查 詢</button>
</div>
</form>
</div>
<script type="text/javascript">
function check() {
var name = document.getElementById("name");;
var sex = document.getElementById("sex");
var min_zu = document.getElementById("min_zu");
var jiao_yu = document.getElementById("jiao_yu");
if(jiao_yu.value == '') {
alert('受教育程度為空');
jiao_yu.focus();
return false;
}
}if(name.value == '') {
alert('戶主名為空');
name.focus();
return false;
}
if(min_zu.value == '') {
alert('民族為空');
min_zu.focus();
return false;
}
if(sex.value == '') {
alert('民族為空');
sex.focus();
return false;
}
}
</script>
</body>
</html>
修改信息
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
Object message = request.getAttribute("message");
if(message!=null && !"".equals(message)){
%>
<script type="text/javascript">
alert("<%=request.getAttribute("message")%>");
</script>
<%} %>
<div align="center">
<h1 style="color: black;">公文信息列表</h1>
<a href="menu.jsp">返回主頁</a>
<table class="tb">
<tr>
<td>id</td>
<td>戶主</td>
<td>身份證號碼</td>
<td>性別</td>
<td>民族</td>
<td>受教育程度</td>
<td>戶別</td>
<td>住房類型</td>
</tr>
<c:forEach items="${peoples}" var="item">
<tr>
<td>${item.id}</td>
<td>${item.name}</td>
<td>${item.idc}</td>
<td>${item.sex}</td>
<td>${item.min_zu}</td>
<td>${item.jiao_yu}</td>
<td>${item.hu_bie}</td>
<td>${item.zhu_fang_lei_bie}</td>
</tr>
</c:forEach>
<form action="Servlet?method=update" method="post" onsubmit="return check()">
<tr>
<td>id<input type="text" id="id" name="id"/></td>
</tr>
<tr>
<td>戶主名<input type="text" id="name" name="name"/></td>
</tr>
<tr>
<td>身份證號<input type="text" id="idc" name="idc" /></td>
</tr>
<tr>
<td>性別<input type="text" id="sex" name="sex" /></td>
</tr>
<tr>
<td>民族<input type="text" id="min_zu" name="min_zu" /></td>
</tr>
<tr>
<td>受教育程度<input type="text" id="jiao_yu" name="jiao_yu" /></td>
</tr>
<tr>
<td><button type="submit" class="b">保存</button></td>
</tr>
</form>
</table>
</div>
<script type="text/javascript">
function check() {
var id = document.getElementById("id");
var idc = document.getElementById("idc");
var name = document.getElementById("name");
var jiao_yu = document.getElementById("jiao_yu");
var min_zu = document.getElementById("min_zu");
var sex = document.getElementById("sex");
//非空
if(id.value == '') {
alert('id為空');
id.focus();
return false;
}
if(jiao_yu.value == '') {
alert('受教育程度為空');
jiao_yu.focus();
return false;
}
if(min_zu.value == '') {
alert('民族為空');
min_zu.focus();
return false;
}
if(idc.value == '') {
alert('身份證號碼為空');
idc.focus();
return false;
}if(name.value == '') {
alert('戶主名為空');
name.focus();
return false;
}
if(sex.value == '') {
alert('性別為空');
sex.focus();
return false;
}
}
</script>
</body>
</html>