parent
3e340d09d1
commit
ef11251d73
@ -0,0 +1,69 @@
|
||||
<%@ 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>
|
||||
<link rel="stylesheet" href="../public/layui/css/layui.css">
|
||||
<script src="../public/layui/layui.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<form class="layui-form layui-form-pane" action="" lay-filter="formFilter">
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">标题</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" name="title" lay-verify="required" required autocomplete="off" placeholder="请输入标题" class="layui-input">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item" style="height:50%;">
|
||||
<label class="layui-form-label">公告</label>
|
||||
<div class="layui-input-block">
|
||||
<textarea name="detail" lay-verify="required" placeholder="请输入公告" autocomplete="off" class="layui-input" style="height:300px;"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<div class="layui-input-block">
|
||||
<button type="submit" class="layui-btn" lay-submit="" lay-filter="submitButton"><i class="layui-icon layui-icon-release" style="font-size: 20px; color: yellow;"></i> 发布</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<script>
|
||||
|
||||
|
||||
layui.use(['form', 'jquery'], function(){
|
||||
$ = layui.jquery;
|
||||
var form = layui.form
|
||||
,layer = layui.layer
|
||||
//监听提交
|
||||
form.on('submit(submitButton)', function(data){
|
||||
$.ajax({
|
||||
url: './announcementAdd',
|
||||
method: 'post',
|
||||
data: data.field,
|
||||
dataType: 'json',
|
||||
success: function(data){
|
||||
if(data.code == "0"){
|
||||
parent.layer.msg("添加成功",{
|
||||
icon: 6,
|
||||
time: 500
|
||||
});
|
||||
setTimeout(function(){
|
||||
parent.location.reload();
|
||||
}, 500);
|
||||
}else{
|
||||
layer.msg(data.msg);
|
||||
}
|
||||
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
return false;
|
||||
});
|
||||
});
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,110 @@
|
||||
<%@ 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">
|
||||
<link rel="stylesheet" href="../public/layui/css/layui.css" media="all">
|
||||
<script src="../public/layui/layui.js"></script>
|
||||
<title>Insert title here</title>
|
||||
</head>
|
||||
<body>
|
||||
<table class="layui-hide" id="annTable" lay-filter="formFilter"></table>
|
||||
|
||||
<script type="text/html" id="headBar">
|
||||
<button type="button" class="layui-btn layui-btn-sm" lay-event="add"><i class="layui-icon"><i class="layui-icon layui-icon-release" style="font-size: 20px; color: yellow;"></i> 发布新公告</i></button>
|
||||
</script>
|
||||
|
||||
<script type="text/html" id="rightBar">
|
||||
<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
|
||||
<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
|
||||
</script>
|
||||
<script>
|
||||
layui.use(['table','jquery'], function(){
|
||||
$ = layui.jquery;
|
||||
var table = layui.table;
|
||||
// 进行渲染
|
||||
var tableIns = table.render({
|
||||
elem: '#annTable'
|
||||
,url:'./announcement'
|
||||
,toolbar: '#headBar'
|
||||
,height: 600
|
||||
,cols: [[
|
||||
{field:'id', width:80, title: 'ID', sort: true}
|
||||
,{field:'title', width:230, title: '标题'}
|
||||
,{field:'detail', width:580, title: '公告'}
|
||||
,{field:'publish_date', title: '发布日期', minWidth: 100, sort: true}
|
||||
,{fixed: 'right', title:'操作', toolbar: '#rightBar', align: 'center', width:150}
|
||||
]]
|
||||
});
|
||||
|
||||
// 头部工具栏事件
|
||||
table.on('toolbar(formFilter)', function(obj){
|
||||
var checkStatus = table.checkStatus(obj.config.id);
|
||||
switch(obj.event){
|
||||
// 添加公告
|
||||
case 'add':
|
||||
var addCardLayer = layer.open({
|
||||
type: 2,
|
||||
title: '发布公告',
|
||||
area: ['800px', '500px'],
|
||||
maxmin: true,
|
||||
shadeClose: true,
|
||||
content: '08add.jsp',
|
||||
});
|
||||
//layer.full(addCardLayer);
|
||||
};
|
||||
});
|
||||
|
||||
// 侧边工具栏事件
|
||||
table.on(('tool(formFilter)'), function(obj){
|
||||
var data = obj.data;
|
||||
var layEvent = obj.event;
|
||||
var id = data.id;
|
||||
var tr = obj.tr;
|
||||
switch(obj.event){
|
||||
case 'edit':
|
||||
layer.open({
|
||||
type: 2,
|
||||
title: '更改信息',
|
||||
area: ['800px', '600px'],
|
||||
maxmin: true,
|
||||
shadeClose: true,
|
||||
content: '08edit.jsp?id=' +id,
|
||||
})
|
||||
break;
|
||||
case 'del':
|
||||
layer.confirm('确定要删除么?',function(){
|
||||
layer.msg("ok");
|
||||
$.ajax({
|
||||
url: './announcementDel',
|
||||
data: 'id=' +id,
|
||||
type: 'get',
|
||||
dataType: 'json',
|
||||
timeout: 3000,
|
||||
success: function(data){
|
||||
layer.msg("???");
|
||||
if(data.code == 0){
|
||||
layer.msg(data.msg,{
|
||||
icon: 6,
|
||||
anim: 5,
|
||||
time: 500
|
||||
});
|
||||
setTimeout(function(){
|
||||
parent.location.reload();
|
||||
},500);
|
||||
}else{
|
||||
layer.msg(data.code);
|
||||
}
|
||||
},
|
||||
error: function(){
|
||||
layer.msg("连接超时");
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
})
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,83 @@
|
||||
<%@page import="java.sql.*"%>
|
||||
<%@page import="javabean.Base"%>
|
||||
<%@ 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">
|
||||
<link rel="stylesheet" href="../public/layui/css/layui.css">
|
||||
<script src="../public/layui/layui.js"></script>
|
||||
<title>Insert title here</title>
|
||||
</head>
|
||||
<body>
|
||||
<jsp:useBean id="check" scope="session" class="javabean.JDBCBean"></jsp:useBean>
|
||||
<%
|
||||
String id = request.getParameter("id");
|
||||
Connection connection = (Connection)Base.getConnection();
|
||||
String sql = "select * from announcement where id=?";
|
||||
PreparedStatement pstmt = connection.prepareCall(sql);
|
||||
pstmt.setString(1,id);
|
||||
ResultSet resultSet = pstmt.executeQuery();
|
||||
resultSet.next();
|
||||
|
||||
%>
|
||||
<form class="layui-form layui-form-pane" action="" lay-filter="formFilter">
|
||||
<input type="text" name="id" value=<%=id %> lay-verify="required" required autocomplete="off" placeholder="请输入姓名" class="layui-input layui-hide">
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">标题</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" name="title" value=<%=resultSet.getString("title") %> lay-verify="required" required autocomplete="off" placeholder="请输入标题" class="layui-input">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">公告</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" name="detail" value=<%=resultSet.getString("detail") %> lay-verify="required" placeholder="请输入公告" autocomplete="off" class="layui-input">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<div class="layui-input-block">
|
||||
<button type="submit" class="layui-btn" lay-submit="" lay-filter="submitButton">立即提交</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<script>
|
||||
|
||||
|
||||
layui.use(['form', 'jquery'], function(){
|
||||
$ = layui.jquery;
|
||||
var form = layui.form
|
||||
,layer = layui.layer
|
||||
//监听提交
|
||||
form.on('submit(submitButton)', function(data){
|
||||
$.ajax({
|
||||
url: './announcementEdit',
|
||||
method: 'post',
|
||||
data: data.field,
|
||||
dataType: 'json',
|
||||
success: function(data){
|
||||
if(data.code == "0"){
|
||||
parent.layer.msg("添加成功",{
|
||||
icon: 6,
|
||||
time: 500
|
||||
});
|
||||
setTimeout(function(){
|
||||
parent.location.reload();
|
||||
}, 500);
|
||||
}else{
|
||||
layer.msg(data.msg);
|
||||
}
|
||||
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
return false;
|
||||
});
|
||||
});
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,149 @@
|
||||
<%@ page import="java.sql.*"%>
|
||||
<%@ page import="java.util.*"%>
|
||||
<%@ 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>
|
||||
</head>
|
||||
<body>
|
||||
<jsp:useBean id="check" scope="session" class="javabean.JDBCBean"></jsp:useBean>
|
||||
<%
|
||||
String psw1 = request.getParameter("psw1");
|
||||
String psw2 = request.getParameter("psw2");
|
||||
String email1 = request.getParameter("email1");
|
||||
String email2 = request.getParameter("email2");
|
||||
String name1 = request.getParameter("name1");
|
||||
String name2 = request.getParameter("name2");
|
||||
|
||||
//out.println(psw1 + " " + psw2);
|
||||
String id = session.getAttribute("manager").toString();
|
||||
|
||||
if(psw1!=null && psw2!=null){
|
||||
if (psw1.equals(psw2) && psw1 != null && psw2 != null && !psw1.trim().equals("")
|
||||
&& !psw2.trim().equals("")) {
|
||||
String sql = "update manager set PASSWORD ='" + psw1 + "' where ACCOUNT='" + id +"'";
|
||||
try {
|
||||
int i = check.executeUpdate(sql);
|
||||
if (i == 1) {
|
||||
%>
|
||||
<script>
|
||||
alert('修改成功!');
|
||||
window.location.href = "09managerSelf.jsp";
|
||||
</script>
|
||||
|
||||
<%
|
||||
} else {
|
||||
%>
|
||||
<script>
|
||||
alert('修改未成功!');
|
||||
window.location.href = "09managerSelf.jsp";
|
||||
</script>
|
||||
<%
|
||||
}
|
||||
} catch (Exception e) {
|
||||
%>
|
||||
<script>
|
||||
alert('修改未成功!');
|
||||
window.location.href = "09managerSelf.jsp";
|
||||
</script>
|
||||
<%
|
||||
}
|
||||
} else {
|
||||
%>
|
||||
<script>
|
||||
alert('修改未成功!');
|
||||
window.location.href = "09managerSelf.jsp";
|
||||
</script>
|
||||
<%
|
||||
}
|
||||
|
||||
|
||||
}else if(email1!=null && email2!=null){
|
||||
//out.println(psw1 + " " + psw2);
|
||||
|
||||
if (email1.equals(email2) && email1 != null && email2 != null && !email1.trim().equals("")
|
||||
&& !email2.trim().equals("")) {
|
||||
String sql = "update manager set EMAIL ='" + email1 + "' where ACCOUNT='" + id +"'";
|
||||
try {
|
||||
int i = check.executeUpdate(sql);
|
||||
if (i == 1) {
|
||||
%>
|
||||
<script>
|
||||
alert('修改成功!');
|
||||
window.location.href = "09managerSelf.jsp";
|
||||
</script>
|
||||
|
||||
<%
|
||||
} else {
|
||||
%>
|
||||
<script>
|
||||
alert('修改未成功!');
|
||||
window.location.href = "09managerSelf.jsp";
|
||||
</script>
|
||||
<%
|
||||
}
|
||||
} catch (Exception e) {
|
||||
%>
|
||||
<script>
|
||||
alert('修改未成功!');
|
||||
window.location.href = "09managerSelf.jsp";
|
||||
</script>
|
||||
<%
|
||||
}
|
||||
} else {
|
||||
%>
|
||||
<script>
|
||||
alert('修改未成功!');
|
||||
window.location.href = "09managerSelf.jsp";
|
||||
</script>
|
||||
<%
|
||||
}
|
||||
|
||||
|
||||
}else if(name1!=null && name2!=null){
|
||||
//out.println(psw1 + " " + psw2);
|
||||
|
||||
if (name1.equals(name2) && name1 != null && name2 != null && !name1.trim().equals("")
|
||||
&& !name2.trim().equals("")) {
|
||||
String sql = "update manager set NAME ='" + name1 + "' where ACCOUNT='" + id +"'";
|
||||
try {
|
||||
int i = check.executeUpdate(sql);
|
||||
if (i == 1) {
|
||||
%>
|
||||
<script>
|
||||
alert('修改成功!');
|
||||
window.location.href = "09managerSelf.jsp";
|
||||
</script>
|
||||
|
||||
<%
|
||||
} else {
|
||||
%>
|
||||
<script>
|
||||
alert('修改未成功!');
|
||||
window.location.href = "09managerSelf.jsp";
|
||||
</script>
|
||||
<%
|
||||
}
|
||||
} catch (Exception e) {
|
||||
%>
|
||||
<script>
|
||||
alert('修改未成功!');
|
||||
window.location.href = "09managerSelf.jsp";
|
||||
</script>
|
||||
<%
|
||||
}
|
||||
} else {
|
||||
%>
|
||||
<script>
|
||||
alert('修改未成功!');
|
||||
window.location.href = "09managerSelf.jsp";
|
||||
</script>
|
||||
<%
|
||||
}
|
||||
}
|
||||
%>
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,73 @@
|
||||
package servlet.manager;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
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 javabean.Base;
|
||||
import javabean.Util;
|
||||
import net.sf.json.JSONArray;
|
||||
import net.sf.json.JSONObject;
|
||||
|
||||
/**
|
||||
* Servlet implementation class Announcement
|
||||
*/
|
||||
@WebServlet("/manager/announcement")
|
||||
public class Announcement extends HttpServlet {
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
resp.setContentType("application/json; charset=utf8");
|
||||
// 准备数据
|
||||
Connection connection = null;
|
||||
PreparedStatement pstmt = null;
|
||||
String sql = "";
|
||||
ResultSet resultSet = null;
|
||||
// 返回数据
|
||||
int code = 1;
|
||||
String msg = "无数据";
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
JSONArray jsonArray = new JSONArray();
|
||||
|
||||
try {
|
||||
connection = (Connection) Base.getConnection();
|
||||
sql = "select * from announcement";
|
||||
pstmt = connection.prepareStatement(sql);
|
||||
resultSet = pstmt.executeQuery();
|
||||
while (resultSet.next()) {
|
||||
jsonObject.put("id", resultSet.getString("id"));
|
||||
jsonObject.put("title", resultSet.getString("title"));
|
||||
jsonObject.put("detail", resultSet.getString("detail"));
|
||||
jsonObject.put("publish_date", resultSet.getString("publish_date"));
|
||||
|
||||
jsonArray.add(jsonObject);
|
||||
}
|
||||
if (!jsonArray.isEmpty()) {
|
||||
code = 0;
|
||||
msg = "查询成功";
|
||||
} else {
|
||||
msg = "数据为空";
|
||||
}
|
||||
} catch (ClassNotFoundException e) {
|
||||
msg = "class找不到";
|
||||
} catch (SQLException e) {
|
||||
msg = "sql错误";
|
||||
} finally {
|
||||
try {
|
||||
Base.closeResource(connection, pstmt, resultSet);
|
||||
} catch (SQLException e) {
|
||||
msg = "关闭失败";
|
||||
}
|
||||
}
|
||||
PrintWriter out = resp.getWriter();
|
||||
out.print(Util.jsonResponse(code, msg, jsonArray.toString()));
|
||||
}
|
||||
}
|
@ -0,0 +1,78 @@
|
||||
package servlet.manager;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
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 javabean.Base;
|
||||
import javabean.DateTime;
|
||||
import net.sf.json.JSONArray;
|
||||
import net.sf.json.JSONObject;
|
||||
|
||||
/**
|
||||
* Servlet implementation class AnnouncementAdd
|
||||
*/
|
||||
@WebServlet("/manager/announcementAdd")
|
||||
public class AnnouncementAdd extends HttpServlet {
|
||||
@Override
|
||||
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
resp.setContentType("application/json; charset=utf8");
|
||||
// 接收参数
|
||||
String id = req.getParameter("id");
|
||||
String tit = req.getParameter("title");
|
||||
String det = req.getParameter("detail");
|
||||
DateTime date = new DateTime();
|
||||
String time = date.show();
|
||||
// 准备参数
|
||||
Connection connection = null;
|
||||
PreparedStatement pstmt = null;
|
||||
ResultSet resultSet = null;
|
||||
int result = 0;
|
||||
int count = 0;
|
||||
// 返回参数
|
||||
int code = 1;
|
||||
String msg = "";
|
||||
|
||||
JSONArray jsonArray = new JSONArray();
|
||||
JSONObject json = new JSONObject();
|
||||
String sql = "insert into announcement(title, detail, publish_date) values(?,?,?)";
|
||||
System.out.println(sql);
|
||||
PrintWriter out = resp.getWriter();
|
||||
try {
|
||||
connection = (Connection) Base.getConnection();
|
||||
pstmt = connection.prepareStatement(sql);
|
||||
pstmt.setString(1, tit);
|
||||
pstmt.setString(2, det);
|
||||
pstmt.setString(3, time);
|
||||
|
||||
result = pstmt.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
Base.closeResource(connection, pstmt, null);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (result == 1) {
|
||||
json.put("code", "0");
|
||||
json.put("msg", "success");
|
||||
} else {
|
||||
json.put("code", "1");
|
||||
json.put("msg", "error");
|
||||
}
|
||||
out.write(json.toString());
|
||||
}
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
package servlet.manager;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
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 javabean.Base;
|
||||
import javabean.Util;
|
||||
|
||||
/**
|
||||
* Servlet implementation class AnnouncementDel
|
||||
*/
|
||||
@WebServlet("/manager/announcementDel")
|
||||
public class AnnouncementDel extends HttpServlet {
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
String id = req.getParameter("id");
|
||||
// 准备参数
|
||||
String sql = "";
|
||||
Connection connection = null;
|
||||
PreparedStatement pstmt = null;
|
||||
ResultSet resultSet = null;
|
||||
int result = 0;
|
||||
// 返回参数
|
||||
int code = 1;
|
||||
String msg = "";
|
||||
PrintWriter out = resp.getWriter();
|
||||
try {
|
||||
connection = (Connection) Base.getConnection();
|
||||
sql = "delete from announcement where id=?";
|
||||
pstmt = connection.prepareStatement(sql);
|
||||
pstmt.setString(1, id);
|
||||
result = pstmt.executeUpdate();
|
||||
if (result == 1) {
|
||||
code = 0;
|
||||
msg = "删除成功";
|
||||
} else {
|
||||
msg = "删除失败";
|
||||
}
|
||||
} catch (ClassNotFoundException e) {
|
||||
msg = "class not found";
|
||||
} catch (SQLException e) {
|
||||
msg = "sql错误";
|
||||
}
|
||||
out.print(Util.jsonResponse(code, msg, null));
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,83 @@
|
||||
package servlet.manager;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
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 javabean.Base;
|
||||
import javabean.Util;
|
||||
import net.sf.json.JSONArray;
|
||||
import net.sf.json.JSONObject;
|
||||
|
||||
/**
|
||||
* Servlet implementation class AnnouncementEdit
|
||||
*/
|
||||
@WebServlet("/manager/announcementEdit")
|
||||
public class AnnouncementEdit extends HttpServlet {
|
||||
@Override
|
||||
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
resp.setContentType("application/json; charset=utf8");
|
||||
// 接收参数
|
||||
String id = req.getParameter("id");
|
||||
String tit = req.getParameter("title");
|
||||
String det = req.getParameter("detail");
|
||||
// 准备参数
|
||||
String sql = "";
|
||||
Connection connection = null;
|
||||
PreparedStatement pstmt = null;
|
||||
ResultSet resultSet = null;
|
||||
int result = 0;
|
||||
// 返回参数
|
||||
int code = 1;
|
||||
String msg = "";
|
||||
PrintWriter out = resp.getWriter();
|
||||
JSONArray jsonArray = new JSONArray();
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
// 进行查询
|
||||
if (tit == null || tit.equals("") || det == null || det.equals("")) {
|
||||
msg = "参数不能为空";
|
||||
out.print(Util.jsonResponse(code, msg, null));
|
||||
} else {
|
||||
try {
|
||||
connection = (Connection) Base.getConnection();
|
||||
// 更新公告
|
||||
sql = "update announcement set title=?, detail=? where id=?";
|
||||
pstmt = connection.prepareStatement(sql);
|
||||
pstmt.setString(1, tit);
|
||||
pstmt.setString(2, det);
|
||||
pstmt.setString(3, id);
|
||||
result = pstmt.executeUpdate();
|
||||
|
||||
// 返回数据
|
||||
if (result == 1) {
|
||||
code = 0;
|
||||
msg = "修改成功";
|
||||
} else {
|
||||
msg = "修改失败";
|
||||
}
|
||||
} catch (ClassNotFoundException e) {
|
||||
msg = "class not found";
|
||||
} catch (SQLException e) {
|
||||
msg = "sql错误";
|
||||
} finally {
|
||||
try {
|
||||
Base.closeResource(connection, pstmt, resultSet);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
out.print(Util.jsonResponse(code, msg, null));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in new issue