提交 7263a46c 编写于 作者: 海马有力量's avatar 海马有力量

finish

上级
Manifest-Version: 1.0
Class-Path:
@CHARSET "UTF-8";
form {
position: relative;
width: 900px;
height: 350px;
}
.txt {
height: 30px;
width: 220px;
}
.d1, .d2, .d3 {
position: absolute;
}
.d1 {
top: 100px;
left: 200px;
}
.d2 {
top: 150px;
left: 200px;
}
.d3 {
top: 200px;
left: 200px;
}
.bt1, .bt2 {
position: absolute;
width: 70px;
height: 30px;
}
.bt1 {
top: 300px;
left: 230px;
}
.bt2 {
top: 300px;
left: 360px;
}
\ No newline at end of file
@CHARSET "UTF-8";
html, body, div, h1, h2, h3, h4, h5, h6, p, span, img, input {
margin: 0;
padding: 0;
}
html, body {
font-size: 19px;
font-family: 'Verdana', 'Arial';
color: rgba(0, 0, 0, 0.8);
}
body {
background: url(../images/bj.jpg) no-repeat;
background-position: center;
background-attachment: fixed;
background-size: 100%;
}
.container {
width: 100%;
height: 100%;
position: relative;
background-image: url(../images/bj.jpg);
background-position: center top;
background-size: cover;
}
.content {
width: 1250px;
height: 650px;
position: absolute;
margin-top: 60px;
margin-left: 100px;
border-radius: 8px;
box-shadow: 0 10px 20px rgba(0, 0, 0, 0.5);
overflow: hidden;
z-index: 1;
padding: 50px;
box-sizing: border-box;
}
.content::before {
content: '';
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
-webkit-filter: blur(20px);
-moz-filter: blur(20px);
-ms-filter: blur(20px);
-o-filter: blur(20px);
filter: blur(20px);
z-index: -1;
margin: -30px;
background-image: url(../images/bj.jpg);
background-position: center top;
background-size: cover;
background-attachment: fixed;
}
.tou{
text-align: center;
height:40px;
}
.zuo{
position:absolute;
left:50px;
border-right:2px solid rgb(224, 224, 224);
width:210px;
height:500px;
}
.btn1{
position:absolute;
margin-top:190px;
left:0;
width:200px;
height:40px;
color:#353535;
}
.btn2{
position:absolute;
margin-top:250px;
left:0;
width:200px;
height:40px;
color:#353535;
}
.you{
position:absolute;
right:50px;
width:940px;
height:500px;
}
.kuang{
width:100%;
height:100%;
}
@CHARSET "UTF-8";
html, body, div, h1, h2, h3, h4, h5, h6, p, span, img, input {
margin: 0;
padding: 0;
}
html, body {
font-size: 22px;
font-family: 'Verdana', 'Arial';
color: rgba(0, 0, 0, 0.8);
}
body {
background: url(../images/timg.jpg) no-repeat;
background-position: center;
background-attachment: fixed;
background-size: 100%;
}
.container {
width: 400px;
height: 350px;
border: 2px solid black;
position: absolute;
left: 50%;
top: 50%;
/* 设置元素的相对于自身的偏移度为负50%(也就是元素自身尺寸的一半)*/
transform: translate(-50%, -50%);
margin: auto;
border-radius: 8px;
background-image: url(../images/timg.jpg);
background-position: center top;
background-size: cover;
}
.content {
width: 400px;
height: 350px;
position: absolute;
left: 0;
top: 0;
bottom: 0;
right: 0;
margin: auto;
box-shadow: 0 10px 20px rgba(0, 0, 0, 0.5);
overflow: hidden;
z-index: 1;
padding: 50px;
box-sizing: border-box;
}
.content::before {
content: '';
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
-webkit-filter: blur(20px);
-moz-filter: blur(20px);
-ms-filter: blur(20px);
-o-filter: blur(20px);
filter: blur(20px);
z-index: -1;
margin: -30px;
background-image: url(../images/timg.jpg);
background-position: center top;
background-size: cover;
background-attachment: fixed;
}
h2{
text-align: center;
}
form{
position:relative;
width:220px;
height:200px;
margin-top:25px;
}
.txt{
width:120px;
float:right;
}
.p1{
margin-top:5px;
float: left;
}
.p2{
margin-top:10px;
float: left;
}
.btn1{
position:absolute;
margin-top:40px;
left:10px;
width:50px;
height:40px;
background:url("bg11.jpg") no-repeat left top;
color:#FFF;
}
.btn2{
position:absolute;
margin-top:40px;
left:80px;
width:50px;
height:40px;
background:url("bg11.jpg") no-repeat left top;
color:#FFF;
}
.btn3{
position:absolute;
margin-top:40px;
margin-left:90px;
width:50px;
height:40px;
background:url("bg11.jpg") no-repeat left top;
color:#FFF;
}
.btn4{
position:absolute;
margin-top:40px;
left:30px;
width:50px;
height:40px;
background:url("bg11.jpg") no-repeat left top;
color:#FFF;
}
.btn5{
position:absolute;
margin-top:40px;
left:120px;
width:50px;
height:40px;
background:url("bg11.jpg") no-repeat left top;
color:#FFF;
}
.txt,submit{
font-family:"Arial", "Tahoma", "微软雅黑", "雅黑";
border:0;
vertical-align:middle;
margin:8px;
line-height:18px;
font-size:18px;
}
/**
*
*/
function queren(){
document.addform.action="Insertjdbc"
document.addform.submit();
}
function quxiao(){
document.addform.action="chakan.jsp"
document.addform.submit();
}
/**
*
*/
function chakan() {
/*document.form.action="chakan.jsp"
document.form.submit();*/
document.getElementById("kuang").src = "chakan.jsp"
}
function add() {
document.getElementById("kuang").src = "add.jsp"
}
function changeFrameHeight() {
var ifm = document.getElementById("kuang");
var height = ifm.height = document.documentElement.clientHeight;
var width = ifm.width = document.documentElement.clientWidth;
}
window.onload = window.onresize = function() {
changeFrameHeight();
}
/**
*
*/
function denglu(){
document.form.action="LoginServlet"
document.form.submit();
}
function quxiao(){
document.form.action="index.jsp"
document.form.submit();
}
function zhuce(){
document.form.action="signup.jsp"
document.form.submit();
}
function queren(){
alert("账户注册成功,请重新登录");
document.form.action="SignServlet"
document.form.submit();
}
function fanhui(){
document.form.action="index.jsp"
document.form.submit();
}
\ No newline at end of file
/**
*
*/
function queren(){
document.addform.action="Updatejdbc"
document.addform.submit();
}
function quxiao(){
document.addform.action="chakan.jsp"
document.addform.submit();
}
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>AddList</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>
\ No newline at end of file
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>添加</title>
<link rel="stylesheet" href="Mycss/add.css"/>
<script type="text/javascript" src="Myjs/add.js"></script>
</head>
<body>
<%
String user=(String)session.getAttribute("user");
if(user==null){
response.sendRedirect("index.jsp");
}
%>
<h2>添加用户</h2>
<div>
<form name="addform">
<div class="d1">
姓名:<input class="txt" type="text" name="name"><br>
</div>
<div class="d2">
电话:<input class="txt" type="text" name="phone"><br>
</div>
<div class="d3">
住址:<input class="txt" type="text" name="address"><br>
</div>
<input class="bt1" type="submit" value="添加" onclick="queren()">
<input class="bt2" type="submit" value="取消" onclick="quxiao()">
</form>
</div>
</body>
</html>
\ No newline at end of file
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>个人通讯录</title>
<link rel="stylesheet" href="Mycss/business.css"/>
<script type="text/javascript" src="Myjs/business.js"></script>
</head>
<body>
<%
String user=(String)session.getAttribute("user");
if(user==null){
response.sendRedirect("index.jsp");
}
%>
<div class="container">
<div class="content">
<div class="tou">
<a href="business.jsp" style="text-decoration:none;color:rgb(0,0,0);">
<h2>个人通讯录</h2>
</a>
</div>
<div class="zuo">
<form name="form1">
<input class="btn1" type="button" value="查看好友" onclick="window.location.href='business.jsp'">
<input class="btn2" type="button" value="添加好友" onclick="window.location.href='insert.jsp'">
</form>
</div>
<div class="you">
<iframe frameborder=no allowtransparency=no class="kuang" id="kuang" src="chakan.jsp"></iframe>
</div>
</div>
</div>
</body>
</html>
\ No newline at end of file
<span style="font-size:12px;"><span style="font-size:14px;"><%@ page language="java" import="java.sql.*,java.io.*,java.util.*"%>
<%@ page contentType="text/html;charset=utf-8"%>
<html>
<head>
<style type="text/css">
table {
border: 2px #CCCCCC solid;
width: 360px;
}
td,th {
height: 30px;
border: #CCCCCC 1px solid;
}
</style>
</head>
<body>
<%
String user=(String)session.getAttribute("user");
if(user==null){
response.sendRedirect("index.jsp");
}
%>
<%
Class.forName("com.mysql.jdbc.Driver");//加载驱动器
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test?serverTimezone=UTC","root","123");
String sql = "select * from addbook";
Statement st = con.createStatement();
ResultSet rs = st.executeQuery(sql);
%>
<%
if(rs.next()){
%>
<table align="center">
<tr>
<th>
<%
out.print("姓名");
%>
</th>
<th>
<%
out.print("电话");
%>
</th>
<th>
<%
out.print("地址");
%>
</th>
<th>
<%
out.print("操作");
%>
</th>
</tr>
<%
do{
%>
<tr>
<td>
<%
out.print(rs.getString(1));
%>
</td>
<td>
<%
out.print(rs.getString(2));
%>
</td>
<td>
<%
out.print(rs.getString(3));
%>
</td>
<td>
<a href="updata.jsp?name=<%=rs.getString(1)%>&phone=<%=rs.getString(2)%>&address=<%=rs.getString(3)%>&key=<%=rs.getString(1)%>">修改</a>
<a href="Deletejdbc?key=<%=rs.getString(1)%>">删除</a>
</td>
</tr>
<%
}while (rs.next());
%>
</table>
<div align="center">
<%
out.print("数据查询成功,恭喜你");
%>
</div>
<%
rs.close();
con.close();
st.close();
%>
<%
} else {
out.print("通讯录没有联络人!请添加好友.");
}
%>
</body>
</html></span><span style="font-size:24px;color: rgb(255, 0, 0);">
</span></span>
\ No newline at end of file
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>个人通讯录</title>
<link rel="stylesheet" href="Mycss/index.css"/>
<script type="text/javascript" src="Myjs/index.js"></script>
</head>
<body>
<div class="container">
<div class="content">
<h2>个人通信录</h2>
<form action="/AddList/LoginServlet" method="POST" name="form">
<p class="p1">用户名:</p><input type="test" name="username"/><br>
<p class="p2">&nbsp;&nbsp;&nbsp;码:</p><input type="password" name="password"/><br>
验证码:<input type="text" name = "check_code"'>
<img src="/AddList/CheckServlet"><br/>
<input class="btn1" type="submit" value="登录"/>
</form>
</div>
</div>
</body>
</html>
\ No newline at end of file
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>个人通讯录</title>
<link rel="stylesheet" href="Mycss/business.css"/>
<script type="text/javascript" src="Myjs/business.js"></script>
</head>
<body>
<%
String user=(String)session.getAttribute("user");
if(user==null){
response.sendRedirect("index.jsp");
}
%>
<div class="container">
<div class="content">
<div class="tou">
<a href="business.jsp" style="text-decoration:none;color:rgb(0,0,0);">
<h2>个人通讯录</h2>
</a>
</div>
<div class="zuo">
<form name="form1">
<input class="btn1" type="button" value="查看好友" onclick="window.location.href='business.jsp'">
<input class="btn2" type="button" value="添加好友" onclick="window.location.href='insert.jsp'">
</form>
</div>
<div class="you">
<iframe frameborder=no allowtransparency=no class="kuang" id="kuang" src="add.jsp"></iframe>
</div>
</div>
</div>
</body>
</html>
\ No newline at end of file
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<style type="text/css">
.d1 {
margin-top: 20px;
border: 1px solid black;
width: 930px;
height: 450px;
border: 1px solid black;
position: relative;
}
.d2 {
position: absolute;
left: 50px;
top: 100px;
}
</style>
</head>
<body>
<%
String user=(String)session.getAttribute("user");
if(user==null){
response.sendRedirect("index.jsp");
}
%>
<div class="d1">
<div class="d2">
<table id="ttt" border="1" width=800px height=200px >
<tr>
<th>姓名</th>
<th>电话</th>
<th>家庭住址</th>
<th colspan="2">操作</th>
</tr>
<tr>
<td align="center">row 1, cell 1</td>
<td align="center">row 1, cell 2</td>
<td align="center">row 1, cell 2</td>
<td align="center"><input type="button" value="修改"></td>
<td align="center"><input type="button" value="删除" onClick="javascript:this.parentNode.parentNode.parentNode.removeChild(this.parentNode.parentNode);"></td>
</tr>
<tr>
<td align="center">row 1, cell 1</td>
<td align="center">row 1, cell 2</td>
<td align="center">row 1, cell 2</td>
<td align="center"><input type="button" value="修改"></td>
<td align="center"><input type="button" value="删除" onClick="javascript:this.parentNode.parentNode.parentNode.removeChild(this.parentNode.parentNode);"></td>
</tr>
<tr>
<td align="center">row 1, cell 1</td>
<td align="center">row 1, cell 2</td>
<td align="center">row 1, cell 2</td>
<td align="center"><input type="button" value="修改"></td>
<td align="center"><input type="button" value="删除" onClick="javascript:this.parentNode.parentNode.parentNode.removeChild(this.parentNode.parentNode);"></td>
</tr>
</table>
</div>
</div>
</body>
</html>
\ No newline at end of file
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>个人通讯录</title>
<link rel="stylesheet" href="Mycss/business.css"/>
<script type="text/javascript" src="Myjs/business.js"></script>
</head>
<body>
<%
String user=(String)session.getAttribute("user");
if(user==null){
response.sendRedirect("index.jsp");
}
%>
<div class="container">
<div class="content">
<div class="tou">
<a href="business.jsp" style="text-decoration:none;color:rgb(0,0,0);">
<h2>个人通讯录</h2>
</a>
</div>
<div class="zuo">
<form name="form1">
<input class="btn1" type="button" value="查看好友" onclick="window.location.href='business.jsp'">
<input class="btn2" type="button" value="添加好友" onclick="window.location.href='insert.jsp'">
</form>
</div>
</div>
</div>
</body>
</html>
\ No newline at end of file
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>修改</title>
<link rel="stylesheet" href="Mycss/add.css"/>
<script type="text/javascript" src="Myjs/updata.js"></script>
</head>
<body>
<%
String user=(String)session.getAttribute("user");
if(user==null){
response.sendRedirect("index.jsp");
}
%>
<h2>修改用户</h2>
<div>
<form name="addform">
<div class="d1">
姓名:<input class="txt" type="text" name="name" value=<%=request.getParameter("name")%>><br>
</div>
<div class="d2">
电话:<input class="txt" type="text" name="phone" value=<%=request.getParameter("phone")%>><br>
</div>
<div class="d3">
住址:<input class="txt" type="text" name="address" value=<%=request.getParameter("address")%>><br>
</div>
<% request.getSession().setAttribute("key",request.getParameter("key"));%>
<input class="bt1" type="submit" value="添加" onclick="queren()" value=<%=request.getParameter("key")%>>
<input class="bt2" type="submit" value="取消" onclick="quxiao()">
</form>
</div>
</body>
</html>
\ No newline at end of file
package cookie;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
@WebServlet("/CheckServlet")
public class CheckServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
private static int width = 60;
private static int height = 20;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
HttpSession session = request.getSession();
response.setContentType("image/jpeg");
ServletOutputStream sos =response.getOutputStream();
response.setHeader("Fragma", "No-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics g = image.getGraphics();
char[] rands = generateCheckCode();
drawBackground(g);
drawRands(g,rands);
g.dispose();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ImageIO.write(image, "JPEG",bos);
byte[] buf = bos.toByteArray();
response.setContentLength(buf.length);
sos.write(buf);
bos.close();
sos.close();
session.setAttribute("check_code", new String(rands));
}
private char[] generateCheckCode(){
String chars = "0123456789qwertyuiopasdfghjklzxcvbnm";
char[] rands =new char[4];
for(int i=0; i<4; i++){
int rand = (int)(Math.random()*36);
rands[i] = chars.charAt(rand);
}
System.out.println(rands);
return rands;
}
private void drawRands(Graphics g, char[] rands){
g.setColor(Color.BLACK);
g.setFont(new Font(null,Font.ITALIC|Font.BOLD,18));
g.drawString(""+rands[0], 1, 17);
g.drawString(""+rands[1], 16,15);
g.drawString(""+rands[2], 31,18);
g.drawString(""+rands[3], 46, 16);
}
private void drawBackground(Graphics g){
g.setColor(new Color(0xDCDCDC));
g.fillRect(0, 0, width, height);
for(int i=0; i<120; i++){
int x = (int)(Math.random()*width);
int y = (int)(Math.random()*height);
int red = (int)(Math.random()*255);
int green = (int)(Math.random()*255);
int blue = (int)(Math.random()*255);
g.setColor(new Color(red,green,blue));
g.drawOval(x, y, 1, 0);
}
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
}
package cookie;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class Deletejdbc
*/
@WebServlet("/Deletejdbc")
public class Deletejdbc extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public Deletejdbc() {
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
response.setContentType("text/html;charset=utf-8");
request.setCharacterEncoding("utf-8");
String name = request.getParameter("key");
try{
Class.forName("com.mysql.jdbc.Driver");//加载驱动器
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test?serverTimezone=UTC","root","123");
PreparedStatement pst = con.prepareStatement("delete from addbook where name=?");
pst.setString(1, name);
int i = pst.executeUpdate();
PrintWriter pw = response.getWriter();
pw.write("信息删除成功,点击链接查看<a href=chakan.jsp>查看所有信息</a>");
con.close();
}catch(Exception ex){
ex.printStackTrace();
}
}
/**
* @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 cookie;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
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.mysql.jdbc.Statement;
/**
* Servlet implementation class Insertjdbc
*/
@WebServlet("/Insertjdbc")
public class Insertjdbc extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public Insertjdbc() {
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
response.setContentType("text/html;charset=utf-8");
request.setCharacterEncoding("utf-8");
String name = request.getParameter("name");
String phone = request.getParameter("phone");
String address = request.getParameter("address");
try{
Class.forName("com.mysql.jdbc.Driver");//加载驱动器
PrintWriter pw = response.getWriter();
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test?serverTimezone=UTC","root","123");
String sql = "select * from addbook where name = ?";
PreparedStatement stat = con.prepareStatement(sql);
stat.setString(1, name);
ResultSet rs = stat.executeQuery();
pw.write(name.length());
if(name.length()==0){
pw.write("名字不能为空,请检查!<a href=add.jsp>点击链接返回</a>");
}
else if(rs.next()){//原数据库是否已存在主码
pw.write("联系人已存在,请检查!<a href=add.jsp>点击链接返回</a>");
}
else {
PreparedStatement pst = con.prepareStatement("insert into addbook(name,phone,address) values(?,?,?)");
pst.setString(1, name);
pst.setString(2, phone);
pst.setString(3, address);
int j = pst.executeUpdate();
pw.write("信息保存成功,点击链接查看<a href=chakan.jsp>查看所有信息</a>");
pst.close();
}
rs.close();
con.close();
pw.close();
}catch(Exception ex){
ex.printStackTrace();
}
}
/**
* @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 cookie;
import java.io.IOException;
import javax.servlet.*;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
/**
* Servlet implementation class LoginServlet
*/
@WebServlet("/LoginServlet")
public class LoginServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public LoginServlet() {
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("gbk");
response.setCharacterEncoding("gbk");
String username=request.getParameter("username");
String passward=request.getParameter("password");
String path="";
String msg="";
if("zhang".equals(username)&&"12345".equals(passward)){
path="success.jsp";
Cookie cookie = new Cookie("username",username);
cookie.setMaxAge(60*60*24);
response.addCookie(cookie);
HttpSession session=request.getSession();
session.setAttribute("user", username);
} else {
path="index.jsp";
msg="Username or Password is Error";
}
request.setAttribute("username", username);
request.setAttribute("msg", msg);
RequestDispatcher dispatchar=request.getRequestDispatcher(path);
dispatchar.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 cookie;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class Insertjdbc
*/
@WebServlet("/Updatejdbc")
public class Updatejdbc extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public Updatejdbc() {
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
response.setContentType("text/html;charset=utf-8");
request.setCharacterEncoding("utf-8");
String key = (String)request.getSession().getAttribute("key");
String name = request.getParameter("name");
String phone = request.getParameter("phone");
String address = request.getParameter("address");
try{
Class.forName("com.mysql.jdbc.Driver");//加载驱动器
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test?serverTimezone=UTC","root","123");
PrintWriter pw = response.getWriter();
String sql = "select * from addbook where name = ?";
PreparedStatement stat = con.prepareStatement(sql);
stat.setString(1, name);
ResultSet rs = stat.executeQuery();
if(name.length()==0){
pw.write("名字不能为空,请检查!<a href=chakan.jsp>点击链接返回</a>");
}
else {
PreparedStatement pstd = con.prepareStatement("delete from addbook where name=?");
pstd.setString(1, key);
int i = pstd.executeUpdate();
con.close();
pstd.close();
Class.forName("com.mysql.jdbc.Driver");//加载驱动器
Connection con1 = DriverManager.getConnection("jdbc:mysql://localhost:3306/test?serverTimezone=UTC","root","123");
PreparedStatement pst = con1.prepareStatement("insert into addbook(name,phone,address) values(?,?,?)");
pst.setString(1, name);
pst.setString(2, phone);
pst.setString(3, address);
int j = pst.executeUpdate();
pw.write("信息修改成功,点击链接查看<a href=chakan.jsp>查看所有信息</a>");
pst.close();
}
rs.close();
con.close();
pw.close();
}catch(Exception ex){
ex.printStackTrace();
}
}
/**
* @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);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册