java web简单的网上名片管理系统
实现名片的增删查改以及回收站中信息的还原与彻底删除
1.登录注册页面
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
登录页面
登录页面
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
登录界面
<%
String InformationA = request.getParameter("name");
String InformationB = request.getParameter("passwd");
if (InformationA == null)
InformationA = "";
else InformationA="";
if (InformationB == null)
InformationB = "";
%>
登录界面
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
登录验证
登录验证
<%
request.setCharacterEncoding("UTF-8");
String Name=request.getParameter("name");
String Passwd=request.getParameter("passwd");
if(!Name.equals("周日")&&!Passwd.equals("123456789")){
%>
登陆成功
<%}else{%>
<%}%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
注册页面
注册页面
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
注册验证
<%
request.setCharacterEncoding("UTF-8");
String Name=request.getParameter("namee");
String Passwd=request.getParameter("passwdd");
if(!Name.equals("周日")&&!Passwd.equals("123456789")){
%>
注册成功
<%}else{%>
<%}%>
2.菜单页面
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
页面标题
网上名片管理系统
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
名片管理主页
名片管理
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
回收站主页
回收站
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
网上名片管理系统
3.名片管理页面
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
增加名片首页
增加名片首页
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@page import="java.sql.*"%>
增加名片
<%
String driver="com.mysql.jdbc.Driver";
String url1="jdbc:mysql://localhost:3306/bbb";
String url2="?user=root&password=2411030483";
String url3="&useUnicode=true&characterEncoding=UTF-8";
String url=url1+url2+url3;
Class.forName(driver);
Connection conn=DriverManager.getConnection(url);
String sql="insert into mingpian(id,name,age,sex,phonenumber) values(?,?,?,?,?);";
%>
<%
request.setCharacterEncoding("UTF-8");
if(request.getParameter("id")!=null&&request.getParameter("id").trim().length()>0&&
request.getParameter("name")!=null&&request.getParameter("name").trim().length()>0){
PreparedStatement pstmt=conn.prepareStatement(sql);//对象
String id2=request.getParameter("id");
String name2=request.getParameter("name");
String age2=request.getParameter("age");
String sex2=request.getParameter("sex");
String phonenumber2=request.getParameter("phonenumber");
int id22=Integer.parseInt(id2);//将数据转换为相应类型
int age22=Integer.parseInt(age2);
pstmt.setInt(1,id22);//将第一个占位符赋值
pstmt.setString(2,name2);
pstmt.setInt(3,age22);
pstmt.setString(4,sex2);
pstmt.setString(5,phonenumber2);
int n=pstmt.executeUpdate();
if(n>0){
%>
<%
out.println("增加成功");
pstmt.close();
conn.close();}
else
{out.println("增加失败");
pstmt.close();
conn.close();}}
%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
查询信息首页
查询信息首页
请输入查询姓氏
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.sql.*" %>
查询信息
<%
String driver="com.mysql.jdbc.Driver";
String url1="jdbc:mysql://localhost:3306/bbb";
String url2="?user=root&password=2411030483";
String url3="&useUnicode=true&characterEncoding=UTF-8";
String url=url1+url2+url3;
Class.forName(driver);
Connection conn=DriverManager.getConnection(url);//实现注册驱动并建立数据库的连接
String sql="select id,name,age,sex,phonenumber from mingpian where name like ?;";//写出对数据库的操作语句,?表示占位符
%>
<%
request.setCharacterEncoding("UTF-8");
if(request.getParameter("name")!=null&&request.getParameter("name").trim().length()>0){
String name2=request.getParameter("name");//通过表单获取数据
PreparedStatement pstmt=conn.prepareStatement(sql);//对象
pstmt.setString(1, name2+"%");//将第一个占位符赋值
ResultSet rs=pstmt.executeQuery();//执行select,返回一个结果集
rs.last();
%>
你要查询的共有<%=rs.getRow()%>人
<%//建立表格,显示数据 %>
记录条数
学号
姓名
年龄
性别
电话号码
<%
rs.beforeFirst();//将信息放入表格
while(rs.next()){
%>
<%=rs.getRow()%>
<%=rs.getInt(1)%>
<%=rs.getString(2)%>
<%=rs.getInt(3)%>
<%=rs.getString(4)%>
<%=rs.getString(5)%>
<%} %>
<%
rs.close();//释放资源,后创建的先释放
pstmt.close();
conn.close();
}
else
out.println("输入异常");
conn.close();
%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
修改信息页面
修改信息页面
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.sql.*"%>
修改信息
<%
String driver = "com.mysql.jdbc.Driver";
String url1 = "jdbc:mysql://localhost:3306/bbb";
String url2 = "?user=root&password=2411030483";
String url3 = "&useUnicode=true&characterEncoding=UTF-8";
String url = url1 + url2 + url3;
Class.forName(driver);
Connection conn = DriverManager.getConnection(url);//实现注册驱动并建立数据库的连接
%>
<%
request.setCharacterEncoding("UTF-8");
String sex=request.getParameter("sex");
String name=request.getParameter("name");
session.setAttribute("sex",sex);
session.setAttribute("name",name);
String sql="select * from mingpian where sex=? and name=?";
PreparedStatement pstmt=conn.prepareStatement(sql);
pstmt.setString(1,sex);
pstmt.setString(2,name);
ResultSet rs = pstmt.executeQuery();
if (rs.next()) {
int id2 = rs.getInt(1);
String name2 = rs.getString(2);
int age2 = rs.getInt(3);
String sex2 = rs.getString(4);
String phonenumber2 = rs.getString(5);
if (rs != null) {
rs.close();
}
if (pstmt != null) {
pstmt.close();
} //释放资源,后创建的先释放
if (conn != null) {
conn.close();
}
%>
<%
} else {
out.print("无合适条件");
if (rs != null) {
rs.close();
}
if (pstmt != null) {
pstmt.close();
} //释放资源,后创建的先释放
if (conn != null) {
conn.close();
}}
%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.sql.*" %>
修改数据库信息
<%
String driver="com.mysql.jdbc.Driver";
String url1="jdbc:mysql://localhost:3306/bbb";
String url2="?user=root&password=2411030483";
String url3="&useUnicode=true&characterEncoding=UTF-8";
String url=url1+url2+url3;
Class.forName(driver);
Connection conn=DriverManager.getConnection(url);//实现注册驱动并建立数据库的连接
%>
<%
String sql="update mingpian set id=?,name=?,age=?,sex=?,phonenumber=? where name=? and sex=?";
PreparedStatement pstmt=conn.prepareStatement(sql);
request.setCharacterEncoding("UTF-8");
int id2=Integer.parseInt(request.getParameter("id2"));
String name2=request.getParameter("name2");
int age2=Integer.parseInt(request.getParameter("age2"));
String sex2=request.getParameter("sex2");
String phonenumber2=request.getParameter("phonenumber2");
String name=(String)session.getAttribute("name");
String sex=(String)session.getAttribute("sex");
pstmt.setInt(1,id2);
pstmt.setString(2,name2);
pstmt.setInt(3,age2);
pstmt.setString(4,sex2);
pstmt.setString(5,phonenumber2);
pstmt.setString(6,name);
pstmt.setString(7,sex);
int n=pstmt.executeUpdate();
if(n>0){%>
数据重写成功!
<%}else{ %>
数据重写失败
<%
}
if(pstmt!=null){pstmt.close();}//释放资源,后创建的先释放
if(conn!=null){conn.close();}
%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
彻底删除信息首页
彻底删除信息首页
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
回收站接收删除信息首页
回收站接收删除到回收站信息首页
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.sql.*"%>
回收站接收删除信息
<%
String driver = "com.mysql.jdbc.Driver";
String url1 = "jdbc:mysql://localhost:3306/bbb";
String url2 = "?user=root&password=2411030483";
String url3 = "&useUnicode=true&characterEncoding=UTF-8";
String url = url1 + url2 + url3;
Class.forName(driver);
Connection conn = DriverManager.getConnection(url);//实现注册驱动并建立数据库的连接
%>
<%
request.setCharacterEncoding("UTF-8");
String id=request.getParameter("id");
String name=request.getParameter("name");
session.setAttribute("id",id);
session.setAttribute("name",name);
String sql="select * from mingpian where id=? and name=?";
PreparedStatement pstmt=conn.prepareStatement(sql);
pstmt.setString(1,id);
pstmt.setString(2,name);
ResultSet rs = pstmt.executeQuery();
if (rs.next()) {
int id2 = rs.getInt(1);
String name2 = rs.getString(2);
int age2 = rs.getInt(3);
String sex2 = rs.getString(4);
String phonenumber2 = rs.getString(5);
if (rs != null) {
rs.close();
}
if (pstmt != null) {
pstmt.close();
} //释放资源,后创建的先释放
if (conn != null) {
conn.close();
}
%>
<%
} else {
out.print("无合适条件");
if (rs != null) {
rs.close();
}
if (pstmt != null) {
pstmt.close();
} //释放资源,后创建的先释放
if (conn != null) {
conn.close();
}}
%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.sql.*"%>
回收站接收删除信息2
<%
String driver="com.mysql.jdbc.Driver";
String url1="jdbc:mysql://localhost:3306/bbb";
String url2="?user=root&password=2411030483";
String url3="&useUnicode=true&characterEncoding=UTF-8";
String url=url1+url2+url3;
Class.forName(driver);
Connection conn=DriverManager.getConnection(url);
String sql="insert into huishou(id,name,age,sex,phonenumber) values(?,?,?,?,?);";
%>
<%
request.setCharacterEncoding("UTF-8");
if(request.getParameter("id2")!=null&&request.getParameter("id2").trim().length()>0&&
request.getParameter("name2")!=null&&request.getParameter("name2").trim().length()>0){
PreparedStatement pstmt=conn.prepareStatement(sql);//对象
String id2=request.getParameter("id2");
String name2=request.getParameter("name2");
String age2=request.getParameter("age2");
String sex2=request.getParameter("sex2");
String phonenumber2=request.getParameter("phonenumber2");
int id22=Integer.parseInt(id2);//将数据转换为相应类型
int age22=Integer.parseInt(age2);
pstmt.setInt(1,id22);//将第一个占位符赋值
pstmt.setString(2,name2);
pstmt.setInt(3,age22);
pstmt.setString(4,sex2);
pstmt.setString(5,phonenumber2);
int n=pstmt.executeUpdate();
if(n>0){
%>
<%
out.println("增加成功");
pstmt.close();
conn.close();
%>
<%
}
else
{out.println("增加失败");
pstmt.close();
conn.close();
}}
%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.sql.*"%>
回收站接收删除信息3
<%
String driver="com.mysql.jdbc.Driver";
String url1="jdbc:mysql://localhost:3306/bbb";
String url2="?user=root&password=2411030483";
String url3="&useUnicode=true&characterEncoding=UTF-8";
String url=url1+url2+url3;
Class.forName(driver);
Connection conn=DriverManager.getConnection(url);//实现注册驱动并建立数据库的连接
String sql="delete from mingpian where id=? and name=?";
%>
<%
request.setCharacterEncoding("UTF-8");//设置字符编码,避免乱码
if(request.getParameter("id")!=null&&request.getParameter("id").trim().length()>0){
PreparedStatement pstmt=conn.prepareStatement(sql);//对象
String id=request.getParameter("id");
String name=request.getParameter("name");
int id2=Integer.parseInt(id);
pstmt.setInt(1,id2);
pstmt.setString(2,name);
int n=pstmt.executeUpdate();
%>
<%
if(n>0) out.println("删除成功");
else out.println("删除失败");
%>
<%
pstmt.close();//释放资源,后创建的先释放
conn.close();}
else{
out.println("输入异常");
conn.close();
}
%>
4.回收站管理页面
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
回收站还原删除信息首页
回收站还原删除到回收站信息首页
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.sql.*"%>
回收站还原删除信息
<%
String driver = "com.mysql.jdbc.Driver";
String url1 = "jdbc:mysql://localhost:3306/bbb";
String url2 = "?user=root&password=2411030483";
String url3 = "&useUnicode=true&characterEncoding=UTF-8";
String url = url1 + url2 + url3;
Class.forName(driver);
Connection conn = DriverManager.getConnection(url);//实现注册驱动并建立数据库的连接
%>
<%
request.setCharacterEncoding("UTF-8");
String id=request.getParameter("id");
String name=request.getParameter("name");
session.setAttribute("id",id);
session.setAttribute("name",name);
String sql="select * from huishou where id=? and name=?";
PreparedStatement pstmt=conn.prepareStatement(sql);
pstmt.setString(1,id);
pstmt.setString(2,name);
ResultSet rs = pstmt.executeQuery();
if (rs.next()) {
int id2 = rs.getInt(1);
String name2 = rs.getString(2);
int age2 = rs.getInt(3);
String sex2 = rs.getString(4);
String phonenumber2 = rs.getString(5);
if (rs != null) {
rs.close();
}
if (pstmt != null) {
pstmt.close();
} //释放资源,后创建的先释放
if (conn != null) {
conn.close();
}
%>
<%
} else {
out.print("无合适条件");
if (rs != null) {
rs.close();
}
if (pstmt != null) {
pstmt.close();
} //释放资源,后创建的先释放
if (conn != null) {
conn.close();
}}
%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.sql.*"%>
回收站还原删除信息2
<%
String driver="com.mysql.jdbc.Driver";
String url1="jdbc:mysql://localhost:3306/bbb";
String url2="?user=root&password=2411030483";
String url3="&useUnicode=true&characterEncoding=UTF-8";
String url=url1+url2+url3;
Class.forName(driver);
Connection conn=DriverManager.getConnection(url);
String sql="insert into mingpian(id,name,age,sex,phonenumber) values(?,?,?,?,?);";
%>
<%
request.setCharacterEncoding("UTF-8");
if(request.getParameter("id2")!=null&&request.getParameter("id2").trim().length()>0&&
request.getParameter("name2")!=null&&request.getParameter("name2").trim().length()>0){
PreparedStatement pstmt=conn.prepareStatement(sql);//对象
String id2=request.getParameter("id2");
String name2=request.getParameter("name2");
String age2=request.getParameter("age2");
String sex2=request.getParameter("sex2");
String phonenumber2=request.getParameter("phonenumber2");
int id22=Integer.parseInt(id2);//将数据转换为相应类型
int age22=Integer.parseInt(age2);
pstmt.setInt(1,id22);//将第一个占位符赋值
pstmt.setString(2,name2);
pstmt.setInt(3,age22);
pstmt.setString(4,sex2);
pstmt.setString(5,phonenumber2);
int n=pstmt.executeUpdate();
if(n>0){
%>
<%
out.println("增加成功");
pstmt.close();
conn.close();
%>
<%
}
else
{out.println("增加失败");
pstmt.close();
conn.close();
}}
%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.sql.*"%>
回收站还原删除信息3
<%
String driver="com.mysql.jdbc.Driver";
String url1="jdbc:mysql://localhost:3306/bbb";
String url2="?user=root&password=2411030483";
String url3="&useUnicode=true&characterEncoding=UTF-8";
String url=url1+url2+url3;
Class.forName(driver);
Connection conn=DriverManager.getConnection(url);//实现注册驱动并建立数据库的连接
String sql="delete from huishou where id=? and name=?";
%>
<%
request.setCharacterEncoding("UTF-8");//设置字符编码,避免乱码
if(request.getParameter("id")!=null&&request.getParameter("id").trim().length()>0){
PreparedStatement pstmt=conn.prepareStatement(sql);//对象
String id=request.getParameter("id");
String name=request.getParameter("name");
int id2=Integer.parseInt(id);
pstmt.setInt(1,id2);
pstmt.setString(2,name);
int n=pstmt.executeUpdate();
%>
<%
if(n>0) out.println("删除成功");
else out.println("删除失败");
%>
<%
pstmt.close();//释放资源,后创建的先释放
conn.close();}
else{
out.println("输入异常");
conn.close();
}
%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
回收站查询信息首页
回收站查询信息首页
请输入查询姓氏
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.sql.*" %>
回收站查询信息
<%
String driver="com.mysql.jdbc.Driver";
String url1="jdbc:mysql://localhost:3306/bbb";
String url2="?user=root&password=2411030483";
String url3="&useUnicode=true&characterEncoding=UTF-8";
String url=url1+url2+url3;
Class.forName(driver);
Connection conn=DriverManager.getConnection(url);//实现注册驱动并建立数据库的连接
String sql="select id,name,age,sex,phonenumber from huishou where name like ?;";//写出对数据库的操作语句,?表示占位符
%>
<%
request.setCharacterEncoding("UTF-8");
if(request.getParameter("name")!=null&&request.getParameter("name").trim().length()>0){
String name2=request.getParameter("name");//通过表单获取数据
PreparedStatement pstmt=conn.prepareStatement(sql);//对象
pstmt.setString(1, name2+"%");//将第一个占位符赋值
ResultSet rs=pstmt.executeQuery();//执行select,返回一个结果集
rs.last();
%>
你要查询的共有<%=rs.getRow()%>人
<%//建立表格,显示数据 %>
记录条数
学号
姓名
年龄
性别
电话号码
<%
rs.beforeFirst();//将信息放入表格
while(rs.next()){
%>
<%=rs.getRow()%>
<%=rs.getInt(1)%>
<%=rs.getString(2)%>
<%=rs.getInt(3)%>
<%=rs.getString(4)%>
<%=rs.getString(5)%>
<%} %>
<%
rs.close();//释放资源,后创建的先释放
pstmt.close();
conn.close();
}
else
out.println("输入异常");
conn.close();
%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
回收站彻底删除信息首页
回收站彻底删除信息首页
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@page import="java.sql.*" %>
回收站彻底删除信息
<%
String driver="com.mysql.jdbc.Driver";
String url1="jdbc:mysql://localhost:3306/bbb";
String url2="?user=root&password=2411030483";
String url3="&useUnicode=true&characterEncoding=UTF-8";
String url=url1+url2+url3;
Class.forName(driver);
Connection conn=DriverManager.getConnection(url);//实现注册驱动并建立数据库的连接
String sql="delete from huishou where id=? and name=?";
%>
<%
request.setCharacterEncoding("UTF-8");//设置字符编码,避免乱码
if(request.getParameter("id")!=null&&request.getParameter("id").trim().length()>0){
PreparedStatement pstmt=conn.prepareStatement(sql);//对象
String id=request.getParameter("id");
String name=request.getParameter("name");
int id2=Integer.parseInt(id);
pstmt.setInt(1,id2);
pstmt.setString(2,name);
int n=pstmt.executeUpdate();
%>
<%
if(n>0) out.println("删除成功");
else out.println("删除失败");
%>
<%
pstmt.close();//释放资源,后创建的先释放
conn.close();}
else{
out.println("输入异常");
conn.close();
}
%>