该系统是一个简单的青年服务管理系统,主要包括了较完整的常用的增删改查以及多条件查询功能,对于初学者有很大帮助。

下面是相关的Java代码、jsp页面、以及数据库的创建和相关表的设计

java代码

首先是相关包的创建,如截图所示(使用的是eclipse软件)

package com.user;

public class User {
private int id;
private String name;
private String sex;
private String mianzu;
private String time;
private String age;
private String mianmao;
private String leibie;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public String getMianzu() {
return mianzu;
}
public void setMianzu(String mianzu) {
this.mianzu = mianzu;
}
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time;
}
public String getAge() {
return age;
}
public void setAge(String age) {
this.age = age;
}
public String getMianmao() {
return mianmao;
}
public void setMianmao(String mianmao) {
this.mianmao = mianmao;
}
public String getLeibie() {
return leibie;
}
public void setLeibie(String leibie) {
this.leibie = leibie;
}
public User() {
super();
// TODO 自动生成的构造函数存根
}
public User(int id, String name, String sex, String mianzu, String time, String age, String mianmao, String leibie) {
super();
this.id = id;
this.name = name;
this.sex = sex;
this.mianzu = mianzu;
this.time = time;
this.age = age;
this.mianmao = mianmao;
this.leibie = leibie;
}
public User(String name, String sex, String mianzu, String time, String age, String mianmao, String leibie) {
super();
this.name = name;
this.sex = sex;
this.mianzu = mianzu;
this.time = time;
this.age = age;
this.mianmao = mianmao;
this.leibie = leibie;
} }
package com.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import com.user.User;
import com.util.DBUtil; public class UserDao {
//添加
public boolean add(User message) {
String sql = "insert into m3(name,sex,mianzu,time,age,mianmao,leibie)"+"values('" + message.getName() + "','"
+ message.getSex() + "','" + message.getMianzu() + "','" + message.getTime() + "','"
+ message.getAge() + "','"+ message.getMianmao()+"','"+ message.getLeibie()+"')";
// 创建数据库链接
Connection conn = DBUtil.getConn();
Statement state = null;
boolean f = false;
int a = 0; try {
state = conn.createStatement();
state.executeUpdate(sql);
} catch (Exception e) {
e.printStackTrace();
} finally {
// 关闭连接
DBUtil.close(state, conn);
} if (a > 0) {
f = true;
}
return f;
}
public static boolean name(String name) {
boolean flag = false;
String sql = "select * from m3 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;
}
//查询
public User search(String name) {
String sql = "select * from m3 where name = '" + name + "'";
Connection conn = DBUtil.getConn();
Statement state = null;
ResultSet rs = null;
User bean=null;
try {
state = conn.createStatement();
rs = state.executeQuery(sql);
while (rs.next()) {
String name2 = rs.getString("name");
String sex2 = rs.getString("sex");
String mianzu2 = rs.getString("mianzu");
String time2 = rs.getString("time");
String age2 = rs.getString("age");
String mianmao2 = rs.getString("mianmao");
String leibie2 = rs.getString("leibie");
bean = new User(name2,sex2,mianzu2,time2,age2,mianmao2,leibie2);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(rs, state, conn);
}
return bean;
}
//删除
public boolean delete(String name){
String sql="delete from m3 where name='" + name + "'";
Connection conn = DBUtil.getConn();
Statement state = null;
int a = 0;
boolean f = false;
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;
}
//通过姓名查找
public static User getUserByName(String name) {
String sql = "select * from m3 where name ='" + name + "'";
Connection conn = DBUtil.getConn();
Statement state = null;
ResultSet rs = null;
User message = null;
try {
state = conn.createStatement();
rs = state.executeQuery(sql);
while (rs.next()) {
String sex = rs.getString("sex");
String mianzu = rs.getString("mianzu");
String time = rs.getString("time");
String age = rs.getString("age");
String mianmao = rs.getString("mianmao");
String leibie = rs.getString("leibie");
message = new User(name,sex,mianzu,time,age,mianmao,leibie);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
DBUtil.close(rs, state, conn);
} return message;
}
//修改
public static boolean update(User message,String m) { String sql = "update m3 set name='" + message.getName() + "', sex='" + message.getSex() + "', mianzu='" + message.getMianzu()+"',time='"+message.getTime()+"',age='"+message.getAge()+"',mianmao='"+message.getMianmao()+"',leibie='" + message.getLeibie() + "'where name ='" + m+ "'";
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;
}
//显示全部
public List<User> list()
{
String sql = "select * from m3";
List<User> list = new ArrayList<>();
Connection conn = DBUtil.getConn();
Statement state = null;
ResultSet rs = null; try {
state = conn.createStatement();
rs = state.executeQuery(sql);
while (rs.next()) {
User bean = null;
String name = rs.getString("name");
String sex = rs.getString("sex");
String mianzu = rs.getString("mianzu");
String time = rs.getString("time");
String age = rs.getString("age");
String mianmao = rs.getString("mianmao");
String leibie = rs.getString("leibie");
bean = new User(name,sex,mianzu,time,age,mianmao,leibie);
list.add(bean);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(rs, state, conn);
} return list;
}
// 综合查询
public List<User> loadview(String sql) {
// TODO Auto-generated method stub
String sql1="select * from m3 "+ sql;
List<User> list =new ArrayList<User>();
Connection con=null;
PreparedStatement psts=null;
ResultSet rs=null;
try
{
con=DBUtil.getConn();
//String sql="select * from course";
psts=con.prepareStatement(sql1);
rs=psts.executeQuery();//记录返回的结果
while(rs.next())
{ String name=rs.getString("name");
String sex=rs.getString("sex");
String mianzu=rs.getString("mianzu");
String time=rs.getString("time");
String age=rs.getString("age");
String mianmao=rs.getString("mianmao");
String leibie=rs.getString("leibie"); User yi=new User(name,sex,mianzu,time,age,mianmao,leibie);
list.add(yi);
} DBUtil.close(rs, psts, con);
} catch (SQLException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
} return list;
}
}
package com.service;

import java.util.List;

import com.dao.UserDao;
import com.user.User; //服务层
public class UserService { UserDao mDao = new UserDao();
//添加
public boolean add(User message) {
boolean f = false;
if(!mDao.name(message.getName())) {
mDao.add(message);
f = true;
}
return f;
}
//查找
public User search(String name) {
return mDao.search(name);
}
//删除
public boolean delete(String name) { mDao.delete(name);
return true;
}
public User getUserByName(String name)
{
return mDao.getUserByName(name);
}
//修改
public void update(User message,String name) {
mDao.update(message,name);
}
public List<User> list()
{
return mDao.list();
}
}
package com.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 com.user.User;
import com.dao.UserDao;
import com.service.UserService; @WebServlet("/UserServlet")
public class UserServlet extends HttpServlet {
static String mo=null;
private static final long serialVersionUID = 1L; UserService service = new UserService(); /**
* 方法选择
*/
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 ("search".equals(method)) {
search(req, resp);
}else if ("delete".equals(method)) {
delete(req, resp);
}else if ("getUserByName".equals(method)) {
getUserByName(req, resp);
}else if ("update".equals(method)) {
update(req, resp);
}else if ("update1".equals(method))
{
update1(req,resp);
}else if ("list".equals(method)) {
list(req, resp);
}
}
//增加
private void add(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
req.setCharacterEncoding("utf-8");
//获取数据
String name = req.getParameter("name");
String sex = req.getParameter("sex");
String mianzu = req.getParameter("mianzu");
String age = req.getParameter("age");
String time = req.getParameter("time");
String mianmao = req.getParameter("mianmao");
String [] leibies = req.getParameterValues("leibie");
StringBuffer buf = new StringBuffer();
for(String leibie : leibies){
buf.append(leibie);
}
String leibie = buf.toString();
User message = new User(name,sex,mianzu,time,age,mianmao,leibie); //添加后消息显示
if(service.add(message)) {
req.setAttribute("message", "添加成功");
req.getRequestDispatcher("zhuye.jsp").forward(req,resp);
} else {
req.setAttribute("message", "姓名重复,请重新录入");
req.getRequestDispatcher("add.jsp").forward(req,resp);
}
}
//查询
private void search(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{
req.setCharacterEncoding("utf-8");
String name = req.getParameter("name");
User message = service.search(name);
if(message == null) {
req.setAttribute("message", "查无此人!");
req.getRequestDispatcher("search.jsp").forward(req,resp);
} else {
req.setAttribute("message", message);
req.getRequestDispatcher("search1.jsp").forward(req,resp);
}
}
//删除
private void delete(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{
req.setCharacterEncoding("utf-8"); //String name=req.getParameter("name");
//if(MessageDao.name(name))
service.delete(mo);
req.setAttribute("message", "删除成功!");
req.getRequestDispatcher("zhuye.jsp").forward(req,resp);
}
//通过姓名查找后删除
private void getUserByName(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{
req.setCharacterEncoding("utf-8");
String name = req.getParameter("name");
User message = service.getUserByName(name);
mo=name;
if(message==null)
{
req.setAttribute("message", "查无此人");
req.getRequestDispatcher("delete.jsp").forward(req, resp);
}
else
{
req.setAttribute("message", message);
req.getRequestDispatcher("delete1.jsp").forward(req,resp);
}
}
//修改
private void update(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{
req.setCharacterEncoding("utf-8");
String name = req.getParameter("name");
User message = UserDao.getUserByName(name);
mo=name;
if(message==null)
{
req.setAttribute("message","查无此人");
req.getRequestDispatcher("update.jsp").forward(req, resp);
}
else
{
req.setAttribute("message",message);
req.getRequestDispatcher("update1.jsp").forward(req,resp);
}
}
//修改
private void update1(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{
req.setCharacterEncoding("utf-8");
String name = req.getParameter("name");
String sex = req.getParameter("sex"); String mianzu = req.getParameter("mianzu");
String age = req.getParameter("age");
String time = req.getParameter("time");
String mianmao = req.getParameter("mianmao");
String [] leibies = req.getParameterValues("leibie");
StringBuffer buf = new StringBuffer();
for(String leibie : leibies){
buf.append(leibie);
}
String leibie = buf.toString();
User message = new User(name,sex,mianzu,time,age,mianmao,leibie);
if(UserDao.update(message,mo))
{
req.setAttribute("message","修改成功");
req.getRequestDispatcher("zhuye.jsp").forward(req,resp);
}
}
//显示全部
private void list(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{
req.setCharacterEncoding("utf-8"); List<User> messages = service.list();
req.setAttribute("messages", messages);
req.getRequestDispatcher("allmessage.jsp").forward(req,resp);
}
}
这个用来实现多条件查询、再今后的学习中,为了方便,我们可以将实现各种方法的servlet都单独写出来。
package com.servlet; import java.io.IOException;
import java.util.ArrayList; 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 com.dao.UserDao;
import com.user.User; /**
* Servlet implementation class Servlet
*/
@WebServlet("/Servlet")
public class Servlet extends HttpServlet {
private static final long serialVersionUID = 1L; /**
* @see HttpServlet#HttpServlet()
*/
public Servlet() {
super();
// TODO Auto-generated constructor stub
} /**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub request.setCharacterEncoding("utf-8");
response.setContentType("textml;charset=utf-8"); UserDao dao=new UserDao();
java.util.List<User> list= new ArrayList<User>();
String p[] = new String[5];//获得条件
String s[] = new String[5];//获得内容
String g[] = new String[5];//获得关系
String f[] = new String[5];//获得精确或者模糊
String number = null; //String number1 = null;
number=request.getParameter("number1");
//number1=request.getParameter("number2");
int n = Integer.parseInt(number);//接收条件的个数
//int n1 = Integer.parseInt(number1);// յĹ ϵ ĸ
for(int i=1;i<=n;i++)
{
p[i]= (String) request.getParameter("s"+i);
s[i]=(String)request.getParameter("shuru"+i);
f[i]=(String)request.getParameter("c"+i); System.out.println("精确还是模糊 "+f[i]);
System.out.println("条件 "+p[i]);
System.out.println("输入 "+s[i]); if(p[i].equals("名字"))
{
p[i] = "name";
}
else if(p[i].equals("性别"))
{
p[i] = "sex";
}else if(p[i].equals("民族"))
{
p[i] = "minzu";
}else if(p[i].equals("注册日期"))
{
p[i] = "time";
}else if(p[i].equals("年龄"))
{
p[i] = "age";
} } for(int i=1;i<n;i++)
{
g[i]=(String) request.getParameter("g"+i);
if(g[i].equals("且")) {
g[i]="and";
}else if(g[i].equals("或")) {
g[i]="or";
} System.out.println("且或"+g[i]);
} String sql="where ";
for(int i=1;i<n;i++)
{
if(s[i].equals(""))
{
continue;
}
if(f[i].equals("精确"))
{
sql=sql+p[i]+"='"+s[i]+"'"+" "+g[i]+" ";
}else if(f[i].equals("模糊"))
{
sql=sql+p[i]+" "+"LIKE"+" "+"'%"+s[i]+"%'"+" "+g[i]+" ";
} } if(f[n].equals("精确"))
{
sql = sql + p[n]+"="+"'"+s[n]+"'";
} else {
sql = sql + p[n]+" "+"LIKE"+" "+"'%"+s[n]+"%'";
}
// }
if(n==1&&s[1].equals(""))
{
System.out.println("什么也没传!");
sql="";
}
list = dao.loadview(sql); if(list.size()==0){
request.setAttribute("message", "查询失败");
request.getRequestDispatcher("search2.jsp").forward(request,response);
}
else {
request.setAttribute("course11",list);
//request.setAttribute("message", "查询成功");
request.getRequestDispatcher("search3.jsp").forward(request,response);
}
} /**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
} }
package com.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement; //数据库连接工具 public class DBUtil { public static String db_url = "jdbc:mysql://localhost:3306/choseuser?useSSL=false&serverTimezone=GMT";
public static String db_user = "root";
public static String db_pass = "";//数据库密码 public static Connection getConn () {
Connection conn = null; try {
Class.forName("com.mysql.jdbc.Driver");//加载驱动
conn = DriverManager.getConnection(db_url, db_user, db_pass);
} catch (Exception e) {
e.printStackTrace();
} return conn;
} /**
* 关闭连接
* @param state
* @param conn
*/
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();
}
}
}
}

jsp

//zhuye.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>主界面</title>
</head>
<style>
a:link {color:blue;}
a:visited {color:blue;}/*选择未访问、已访问、悬浮和活动链接,并设置它们的样式:*/
a:hover {color:red;}
a{
font-size:22px;
font-family:"楷体";/*设置字体*/
font-weight:2px;
}
h1
{
color:red;
font-size:44px;}
</style>
<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>
</div>
<div align="center">
<div class="a">
<a href="add.jsp">信息登记</a>
</div>
<div class="a">
<a href="search.jsp">查询信息</a>
</div>
<div class="a">
<a href="delete.jsp">信息删除</a>
</div> <div class="a">
<a href="update.jsp">信息修改</a>
</div>
<div class="a">
<a href="UserServlet?method=list">基本信息</a>
</div>
<div class="a">
<a href="search2.jsp">综合查询</a>
</div>
</div>
</body>
</html>
//add.jsp
<%@ 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="zhuye.jsp">返回主页</a>
<form action="UserServlet?method=add" method="post" onsubmit="return check()">
<div class="a">
姓名:<input type="text" id="name" name="name" />
</div>
<div class="a">
性别: <input type="radio" id="sex" name="sex" value="男">男
<input type="radio" id="sex"name="sex" value="女">女
</div>
<div class="a">
民族:<input type="text" id="mianzu" name="mianzu" style=" border-color:Lime;border-radius:6px;" required="required" />
</div>
<div class="a">
注册时间:<input type="date" id="time" name="time" />
</div>
<div class="a">
年龄:<input type="text" id="age" name="age" />
</div>
<div class="a">
政治面貌:<select name="mianmao" id="mianmao" >
<option value="群众" >群众</option>
<option value="共青团员" >共青团员</option>
<option value="中共党员">中共党员</option>
</select>
</div>
<div class="a" >
服务类别:
<div>
<input type="checkbox" name="leibie" id="leibie" value="扶危济困"/>扶危济困
<input type="checkbox" name="leibie" id="leibie" value="敬老助残"/>敬老助残
<input type="checkbox" name="leibie" id="leibie" value="社区服务"/>社区服务
<input type="checkbox" name="leibie" id="leibie" value="秩序维护"/>秩序维护
</div>
<div>
<input type="checkbox" name="leibie" id="leibie" value="文体服务"/>文体服务
<input type="checkbox" name="leibie" id="leibie" value="环境保护"/>环境保护
<input type="checkbox" name="leibie" id="leibie" value="治安防范"/>治安防范
<input type="checkbox" name="leibie" id="leibie" value="医疗救治"/>医疗救治
</div>
<div>
<input type="checkbox" name="leibie" id="leibie" value="法律援助"/>法律援助
<input type="checkbox" name="leibie" id="leibie" value="大型活动"/>大型活动
<input type="checkbox" name="leibie" id="leibie" value="心理疏导"/>心理疏导
<input type="checkbox" name="leibie" id="leibie" value="精神抚慰"/>精神抚慰
</div>
<div>
<input type="checkbox" name="leibie" id="leibie" value="支教支医"/>支教支医
<input type="checkbox" name="leibie" id="leibie" value="科学普及"/>科学普及
<input type="checkbox" name="leibie" id="leibie" value="应急救援"/>应急救援
<input type="checkbox" name="leibie" id="leibie" value="便民服务"/>便民服务
</div>
<div>
<input type="checkbox" name="leibie" id="leibie" value="民事调解"/>民事调解
<input type="checkbox" name="leibie" id="leibie" value="文明引导"/>文明引导
<input type="checkbox" name="leibie" id="leibie" value="安全生产"/>安全生产
<input type="checkbox" name="leibie" id="leibie" value="禁毒宣传"/>禁毒宣传
</div>
</div>
<div class="a">
<button type="submit" class="b">保存</button>
<input type="reset" value="重置" />
</div>
</form>
<script type="text/javascript">
function check() {
var name = document.getElementById("name");
var sex = document.getElementById("sex");
var mianzu = document.getElementById("mianzu");
var time= document.getElementById("time");
var age = document.getElementById("age");
var mianmao= document.getElementById("mianmao");
//非空
if(name.value == '') {
alert('性名不能为空');
name.focus();
return false;
}
if(sex.value == '') {
alert('性别不能为空');
sex.focus();
return false;
}
if(mianzu.value == '') {
alert('民族不能为空');
mianzu.focus();
return false;
}
if(time.value == '') {
alert('注册时间不能为空');
time.focus();
return false;
}
if(mianmao.value == '') {
alert('面貌不能为空');
mianmao.focus();
return false;
}
if(leibie.value == '') {
alert('类别不能为空');
leibie.focus();
return false;
}
var obj=document.getElementsByName("leibie");
var num=0;
for (var i=0;i<obj.length ;i++ )
if (obj[i].checked )
num+=1;
if (num>4)
{
alert("最多可以选择四个!");
return false;
} }
</script>
</body>
</html>
delete.jsp
<%@ 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="zhuye.jsp">返回主页</a>
<form action="UserServlet?method=getUserByName" 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>
delete1.jsp
<%@ 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="zhuye.jsp">返回主页</a>
<table class="tb">
<tr>
<td>姓名:${message.name}</td>
</tr>
<tr>
<td>性别:${message.sex}</td>
</tr>
<tr>
<td>民族:${message.mianzu}</td>
</tr>
<tr>
<td>注册时间:${message.time}</td>
</tr>
<tr>
<td>年龄:${message.age}</td>
</tr>
<tr>
<td>政治面貌:${message.mianmao}</td>
</tr>
<tr>
<td >服务类别:${message.leibie}</td>
</tr>
</table>
<div class="a">
<a onclick="return check()" href="UserServlet?method=delete" method="post"">删除</a>
</div>
</div>
<script type="text/javascript">
function check() {
if (confirm("是否删除?")){
return true;
}else{
return false;
}
}
</script>
</body>
</html>
search.jsp
<%@ 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="zhuye.jsp">返回主页</a>
<form action="UserServlet?method=search" 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('请输入姓名');
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>
<div align="center">
<h1 style="color: black;">信息列表</h1>
<a href="zhuye.jsp">返回主页</a>
<table class="tb">
<tr>
<td>姓名:${message.name}</td>
</tr>
<tr>
<td>性别:${message.sex}</td>
</tr>
<tr>
<td>民族:${message.mianzu}</td>
</tr>
<tr>
<td>注册时间:${message.time}</td>
</tr>
<tr>
<td>年龄:${message.age}</td>
<tr>
<td>政治面貌:${message.mianmao}</td>
</tr>
<tr>
<td>服务类别:${message.leibie}</td>
</tr>
</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> <script>
var i=1;
var j=1;
document.getElementById('number1').value=i;
document.getElementById('number2').value=j;
function demoDisplay(){
if(document.getElementById("p2").style.display=="none"){
i++;
j++;
document.getElementById("p2").style.display="inline";
document.getElementById('number1').value=i;
document.getElementById('number2').value=j;
// alert(i);
// alert(j);
return;
}else if(document.getElementById("p3").style.display=="none")
{
i++;
j++;
document.getElementById("p3").style.display="inline";
document.getElementById('number1').value=i;
document.getElementById('number2').value=j;
// alert(i);
// alert(j);
return;
}else if(document.getElementById("p4").style.display=="none")
{
i++;
j++;
document.getElementById("p4").style.display="inline";
document.getElementById('number1').value=i;
document.getElementById('number2').value=j;
// alert(i);
// alert(j);
return;
}else if(document.getElementById("p5").style.display=="none")
{
i++;
j++;
document.getElementById("p5").style.display="inline";
document.getElementById('number1').value=i;
document.getElementById('number2').value=j;
// alert(i);
// alert(j);
return;
}
}
function demoVisibility(){
if(document.getElementById("p5").style.display=="inline")
{
i--;
j--;
document.getElementById("p5").style.display="none";
document.getElementById('number1').value=i;
document.getElementById('number2').value=j;
//System.out.println("i:"+i+"j"+j);
return;
}else if(document.getElementById("p4").style.display=="inline")
{
i--;
j--;
document.getElementById("p4").style.display="none";
document.getElementById('number1').value=i;
document.getElementById('number2').value=j;
//System.out.println("i:"+i+"j"+j);
return;
}else if(document.getElementById("p3").style.display=="inline")
{
i--;
j--;
document.getElementById("p3").style.display="none";
document.getElementById('number1').value=i;
document.getElementById('number2').value=j;
//System.out.println("i:"+i+"j"+j);
return;
}else if(document.getElementById("p2").style.display=="inline")
{
i--;
j--;
document.getElementById("p2").style.display="none";
document.getElementById('number1').value=i;
document.getElementById('number2').value=j;
//System.out.println("i:"+i+"j"+j);
return;
}
}
</script> </head>
<body>
<%
Object message=request.getAttribute("message");
if(message!=null&&!"".equals(message)){
%> <script type="text/javascript">
alert("<%=request.getAttribute("message")%>");
</script>
<%}%>
<form action="Servlet" method="post">
<br>
&nbsp;&nbsp;
<button type="button" onclick="demoDisplay()" class="layui-btn layui-btn-primary layui-btn-sm"><i class="layui-icon">+</i></button>
<button type="button" onclick="demoVisibility()" class="layui-btn layui-btn-primary layui-btn-sm"><i class="layui-icon">-</i></button><br> &nbsp;&nbsp;
<div id="p1">
&nbsp;&nbsp;
<select name="g22" style="visibility:hidden">
<option value="且">且</option>
<option value="或">或</option>
</select>
<select name="s1" >
<option>名字</option>
<option>性别</option>
<option>民族</option>
<option>注册日期</option>
<option>年龄</option>
</select>
<input type="text" name="shuru1" value="" />
<select name="c1">
<option>精确</option>
<option>模糊</option>
</select>
<br>
</div> <div id="p2" style="display:none">
&nbsp;&nbsp;
<select name="g1" >
<option value="且">且</option>
<option value="或">或</option>
</select>
<select name="s2">
<option>名字</option>
<option>性别</option>
<option>民族</option>
<option>注册日期</option>
<option>年龄</option>
</select>
<input type="text" name="shuru2" value="" />
<select name="c2">
<option>精确</option>
<option>模糊</option>
</select>
<br>
</div> <div id="p3" style="display:none">
&nbsp;&nbsp;
<select name="g2">
<option value="且">且</option>
<option value="或">或</option>
</select>
<select name="s3">
<option>名字</option>
<option>性别</option>
<option>民族</option>
<option>注册日期</option>
<option>年龄</option>
</select>
<input type="text" name="shuru3" value="" />
<select name="c3">
<option>精确</option>
<option>模糊</option>
</select>
<br>
</div> <div id="p4" style="display:none">
&nbsp;&nbsp;
<select name="g3">
<option value="且">且</option>
<option value="或">或</option>
</select>
<select name="s4">
<option>名字</option>
<option>性别</option>
<option>民族</option>
<option>注册日期</option>
<option>年龄</option>
</select>
<input type="text" name="shuru4" value="" />
<select name="c4">
<option>精确</option>
<option>模糊</option>
</select>
<br>
</div> <div id="p5" style="display:none">
&nbsp;&nbsp;
<select name="g4">
<option value="且">且</option>
<option value="或">或</option>
</select>
<select name="s5">
<option>名字</option>
<option>性别</option>
<option>民族</option>
<option>注册日期</option>
<option>年龄</option>
</select>
<input type="text" name="shuru5" value="" />
<select name="c5">
<option>精确</option>
<option>模糊</option>
</select>
</div>
<p hidden>
<input type="text" value="1" id="number1" name="number1">
<input type="text" value="1" id="number2" name="number2">
</p>
<br>
<input type="submit" name="submit" value="查询" >
</form>
<br>
<h4 align="left">
<%-- 一共查询到了<span style="color:red"><%=list.size() %></span>条数据 --%>
</h4>
<table class="table table-striped">
</table> </body>
</html>
<%@ page language="java" contentType="text/html; charse=tUTF-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>
<a href="zhuye.jsp">返回主界面</a>
<%
Object message=request.getAttribute("message");
if(message!=null&&!"".equals(message)){
%> <script type="text/javascript">
alert("<%=request.getAttribute("message")%>");
</script>
<%}%>
<table>
<tr>
<td>姓名</td>
<td>性别</td>
<td>民族</td>
<td>注册日期</td>
<td>年龄</td>
<td>政治面貌</td>
<td>服务类别</td>
</tr>
<c:forEach items="${course11}" var="course1">
<tr>
<td>${course1.name}</td>
<td>${course1.sex}</td>
<td>${course1.mianzu}</td>
<td>${course1.time}</td>
<td>${course1.age}</td>
<td>${course1.mianmao}</td>
<td>${course1.leibie}</td> </tr>
</c:forEach>
</table>
</body>
</html>
update.jsp
<%@ 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="zhuye.jsp">返回主页</a>
        <form action="UserServlet?method=update" 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>
//update1.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>信息修改</title> </head>
<body>
<div align="center">
<h1 style="color: black;">信息修改</h1>
<a href="zhuye.jsp">返回主页</a>
<form action="UserServlet?method=update1" method="post" onsubmit="return check()">
<div class="a">
姓名:<input type="text" id="name" name="name" value="${message.name}"/>
</div>
<div class="a">
性别:<input type="radio" id="sex" name="sex" value="男"
<c:if test="${message.sex==\"男\"}">checked</c:if>>男
<input type="radio" id="sex" name="sex" value="女"
<c:if test="${message.sex==\"女\"}">checked</c:if>>女
</div>
<div class="a">
民族:<input type="text" id="mianzu" name="mianzu" value="${message.mianzu}"/>
</div>
<div class="a">
注册时间:<input type="date" id="time" name="time" value="${message.time}"/>
</div>
<div class="a">
年龄:<input type="text" id="age" name="age" value="${message.age}"/>
</div>
<div class="a">
政治面貌: <select name="mianmao" id="mianmao" >
<option value="群众" <c:if test="${message.mianmao==\"群众\"}">selected</c:if>>群众</option>
<option value="共青团员" <c:if test="${message.mianmao==\"共青团员\"}">selected</c:if>>共青团员</option>
<option value="中共党员" <c:if test="${message.mianmao==\"中共党员\"}">selected</c:if>>中共党员</option>
</select>
</div>
<div class="a">
服务类别:
<div>
<input type="checkbox" name="leibie" id="leibie" value="扶危济困"/>扶危济困
<input type="checkbox" name="leibie" id="leibie" value="敬老助残"/>敬老助残
<input type="checkbox" name="leibie" id="leibie" value="社区服务"/>社区服务
<input type="checkbox" name="leibie" id="leibie" value="秩序维护"/>秩序维护
</div>
<div>
<input type="checkbox" name="leibie" id="leibie" value="文体服务"/>文体服务
<input type="checkbox" name="leibie" id="leibie" value="环境保护"/>环境保护
<input type="checkbox" name="leibie" id="leibie" value="治安防范"/>治安防范
<input type="checkbox" name="leibie" id="leibie" value="医疗救治"/>医疗救治
</div>
<div>
<input type="checkbox" name="leibie" id="leibie" value="法律援助"/>法律援助
<input type="checkbox" name="leibie" id="leibie" value="大型活动"/>大型活动
<input type="checkbox" name="leibie" id="leibie" value="心理疏导"/>心理疏导
<input type="checkbox" name="leibie" id="leibie" value="精神抚慰"/>精神抚慰
</div>
<div>
<input type="checkbox" name="leibie" id="leibie" value="支教支医"/>支教支医
<input type="checkbox" name="leibie" id="leibie" value="科学普及"/>科学普及
<input type="checkbox" name="leibie" id="leibie" value="应急救援"/>应急救援
<input type="checkbox" name="leibie" id="leibie" value="便民服务"/>便民服务
</div>
<div>
<input type="checkbox" name="leibie" id="leibie" value="民事调解"/>民事调解
<input type="checkbox" name="leibie" id="leibie" value="文明引导"/>文明引导
<input type="checkbox" name="leibie" id="leibie" value="安全生产"/>安全生产
<input type="checkbox" name="leibie" id="leibie" value="禁毒宣传"/>禁毒宣传
</div>
</div>
<div class="a">
<input type="submit" class="b" value="修改" />
<button type="button" onclick="location.href='zhuye.jsp'" class="b">返回</button>
</div>
</div>
</form>
<script type="text/javascript">
function check() {
var name = document.getElementById("name");
var sex = document.getElementById("sex");
var mianzu = document.getElementById("mianzu");
var time= document.getElementById("time");
var age = document.getElementById("age");
var mianmao= document.getElementById("mianmao");
//非空
if(name.value == '') {
alert('性名不能为空');
name.focus();
return false;
}
if(sex.value == '') {
alert('性别不能为空');
sex.focus();
return false;
}
if(mianzu.value == '') {
alert('民族不能为空');
mianzu.focus();
return false;
}
if(time.value == '') {
alert('注册时间不能为空');
time.focus();
return false;
}
var obj=document.getElementsByName("leibie");
var num=0;
for (var i=0;i<obj.length ;i++ )
if (obj[i].checked )
num+=1;
if (num>4)
{
alert("服务类别最多可以选择四个!");
return false;
} } </script>
</body>
</html>
allmessage.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>所有信息</title>
<style>
.tb, td {
border: 1px solid black;
font-size: 22px;
}
</style>
</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="zhuye.jsp">返回主页</a>
<table class="tb">
<tr>
<td>姓名</td>
<td>性别</td>
<td>民族</td>
<td>政治面貌</td>
</tr>
<!-- forEach遍历出adminBeans -->
<c:forEach items="${messages}" var="item" >
<tr>
<td><a href="UserServlet?method=search&&name=${item.name}">${item.name}</a></td>
<td>${item.sex}</td>
<td>${item.mianzu}</td>
<td>${item.mianmao}</td>
<td><a href="UserServlet?method=update&&name=${item.name}">修改</a></td>
<td><a href="UserServlet?method=delete&&name=${item.name}">删除</a></td>
<td><a href="UserServlet?method=search&&name=${item.name}">详细信息</a></td>
</tr>
</c:forEach>
</table>
</div>
</body>
</html>

数据库、表的设计

以上就是整个系统的全部内容了,供参考。

JavaWeb系统(增删改查、多条件查询功能)的更多相关文章

  1. 【hbase】——Java操作Hbase进行建表、删表以及对数据进行增删改查,条件查询

    1.搭建环境 新建JAVA项目,添加的包有: 有关Hadoop的hadoop-core-0.20.204.0.jar 有关Hbase的hbase-0.90.4.jar.hbase-0.90.4-tes ...

  2. (转)Java操作Hbase进行建表、删表以及对数据进行增删改查,条件查询

    1.搭建环境 新建JAVA项目,添加的包有: 有关Hadoop的hadoop-core-0.20.204.0.jar 有关Hbase的hbase-0.90.4.jar.hbase-0.90.4-tes ...

  3. Java操作Hbase进行建表、删表以及对数据进行增删改查,条件查询

    1.搭建环境 新建JAVA项目,添加的包有: 有关Hadoop的hadoop-core-0.20.204.0.jar 有关Hbase的hbase-0.90.4.jar.hbase-0.90.4-tes ...

  4. HBase之四--(1):Java操作Hbase进行建表、删表以及对数据进行增删改查,条件查询

    1.搭建环境 新建JAVA项目,添加的包有: 有关Hadoop的hadoop-core-0.20.204.0.jar 有关Hbase的hbase-0.90.4.jar.hbase-0.90.4-tes ...

  5. php连接数据库增删改查----多条件查询

    关于查询,可以直接写在主页面上 来进行查询 首先,先建立一个表单 <form method="post" action="crud.php"> &l ...

  6. SQL server 创建 修改表格 及表格基本增删改查 及 高级查询 及 (数学、字符串、日期时间)函数[转]

    SQL server 创建 修改表格 及表格基本增删改查 及 高级查询 及 (数学.字符串.日期时间)函数   --创建表格 create table aa ( UserName varchar(50 ...

  7. JAVAWEB之增删改查

    青年志愿者服务网(20分)   1.项目需求: 为了适应社会主义市场经济发展的需要,推动青年志愿服务体系和多层次社会保障体系的建立和完善,促进青年健康成长,石家庄铁道大学急需建设青年志愿者服务网,推进 ...

  8. 【gridview增删改查】数据库查询后lodop打印

    ASP.NET中使用gridview可以很容易的把需要的数据动态显示在前台,还可以在表格里加入列进行增删改查,每次点击的时候重新加载数据,gridview也提供了分页等功能,还有一些模版让显示在前台的 ...

  9. 增删改查- 万能map- 模糊查询

    1.编写接口 2.编写对应的mapper种的sql语句 3.测试 接口 public interface UserDao { List<User> getUserList(); //根据I ...

  10. LINQ的增删改查写法&&组合查询

    .ToList();//返回一个集合,包含查到的所有值: .First();//返回查到的第一条数据,如果查不到会报错: .FirstOrDefault();返回查到的第一条数据,差不到返回一个nul ...

随机推荐

  1. H3C 不适当的VLAN间路由方式

  2. Linux内存页大小

    当使用内存时, 记住一个内存页是 PAGE_SIZE 字节, 不是 4KB. 假定页大小是 4KB 并且 硬编码这个值是一个 PC 程序员常见的错误, 相反, 被支持的平台显示页大小从 4 KB 到 ...

  3. OpenWrt Kernel Module Creation Howto

    OpenWrt Kernel Module Creation Howto About OpenWrt Kernel Module Compilation You are planning to com ...

  4. HDU3669 Aragorn's Story 树链剖分 点权

    HDU3669 Aragorn's Story 树链剖分 点权 传送门:http://acm.hdu.edu.cn/showproblem.php?pid=3966 题意: n个点的,m条边,每个点都 ...

  5. 学习Java第四周

    复习数组,数组和方法在内存中是怎样存储这个问题,有些一知半解. 复习了面向对象思想,是面向对象思想,类的定义,对象实例化,构造函数,还有用javabean的格式定义类.面向过程是自己解决问题,面向对象 ...

  6. windows下使用cmake+mingw配置makefile

    前面一节说了cmake简易使用,但是实际开发中项目文件非常多,使用哪种简易方式会导致代码十分混乱,因此本文介绍一种cmake管理大型项目的demo流程. 具体步骤如下: 1.创建相关的项目目录 cmd ...

  7. (转)hibernate缓存机制详细分析

    在本篇随笔里将会分析一下hibernate的缓存机制,包括一级缓存(session级别).二级缓存(sessionFactory级别)以及查询缓存,当然还要讨论下我们的N+1的问题. 随笔虽长,但我相 ...

  8. Struts2和Spring集成

    Spring是一个流行的Web框架,它提供易于集成与很多常见的网络任务.所以,问题是,为什么我们需要Spring,当我们有Struts2?Spring是超过一个MVC框架 - 它提供了许多其它好用的东 ...

  9. Linux使用expect和rsync实现密码自动输入无人值守自动同步备份

    我们常用sudo,ssh.ftp命令操作服务器或者修改权限的时候都会要求输入password,但是shell脚本运行中该如何交互实现自动输入密码呢? 下面总结三种实现方法. 一.重定向:用重定向方法实 ...

  10. 缓存一致性协议(MESI)

    在目前主流的计算机中,cpu执行计算的主要流程如图所示: 数据加载的流程如下: 1.将程序和数据从硬盘加载到内存中 2.将程序和数据从内存加载到缓存中(目前多三级缓存,数据加载顺序:L3->L2 ...