web.xml and charset

pull/1/head
xicheny 5 years ago
parent b41b1acf21
commit c47d51dc55

@ -1,6 +1,6 @@
<%@page import="javabean.Util"%> <%@page import="javabean.Util"%>
<%@page import="java.sql.PreparedStatement"%> <%@page import="java.sql.PreparedStatement"%>
<%@page import="com.mysql.jdbc.Connection"%> <%@page import="java.sql.Connection"%>
<%@page import="javabean.Base"%> <%@page import="javabean.Base"%>
<%@page import="java.sql.ResultSet"%> <%@page import="java.sql.ResultSet"%>
<%@page import="javabean.JDBCBean"%> <%@page import="javabean.JDBCBean"%>

@ -135,7 +135,7 @@
}else{ }else{
%> %>
<script> <script>
alert('借阅证已挂失或注销'); alert('借阅证已挂失!');
window.location.href = "02borrow.jsp"; window.location.href = "02borrow.jsp";
</script> </script>
<% <%

@ -98,7 +98,7 @@
<p><span class="glyphicon glyphicon-star-empty">&nbsp;状态: <p><span class="glyphicon glyphicon-star-empty">&nbsp;状态:
<% <%
if(rs.getString("STATUS").equals("1")){ if(rs.getString("STATUS").equals("1")){
out.println("正常"); out.println("可用");
} }
else{ else{
out.println("挂失"); out.println("挂失");

@ -2,6 +2,7 @@ package servlet.admin;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
@ -12,8 +13,6 @@ import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.sql.Connection;
import javabean.Base; import javabean.Base;
import net.sf.json.JSONArray; import net.sf.json.JSONArray;
import net.sf.json.JSONObject; import net.sf.json.JSONObject;
@ -25,19 +24,19 @@ import net.sf.json.JSONObject;
public class CardList extends HttpServlet { public class CardList extends HttpServlet {
@Override @Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.setContentType("application/json; charset:utf8"); resp.setContentType("application/json; charset=utf8");
// 接收参数 // 接收参数
String limit = req.getParameter("limit"); String limit = req.getParameter("limit");
String page = req.getParameter("page"); String page = req.getParameter("page");
String condition = (String) req.getParameter("condition"); String condition = (String) req.getParameter("condition");
String conditionValue = (String) req.getParameter("conditionValue"); String conditionValue = (String) req.getParameter("conditionValue");
String where = null; // 无限制条件 String where = null; // 无限制条件
if(page == null) { if (page == null) {
page = "1"; page = "1";
} }
if(limit == null) { if (limit == null) {
limit = "10"; limit = "10";
} }
Connection connection = null; Connection connection = null;
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet resultSet = null; ResultSet resultSet = null;
@ -45,7 +44,7 @@ public class CardList extends HttpServlet {
String msg = "error"; String msg = "error";
int count = 0; int count = 0;
String sql = ""; String sql = "";
//String countSql = "" // String countSql = ""
JSONObject jsonObject = new JSONObject(); JSONObject jsonObject = new JSONObject();
JSONArray jsonArray = new JSONArray(); JSONArray jsonArray = new JSONArray();
JSONObject jsonResult = new JSONObject(); JSONObject jsonResult = new JSONObject();
@ -54,20 +53,20 @@ public class CardList extends HttpServlet {
connection = (Connection) Base.getConnection(); connection = (Connection) Base.getConnection();
sql = "select id,password,reader,rule_id,status from borrow_card"; sql = "select id,password,reader,rule_id,status from borrow_card";
// where // where
if(condition != null && conditionValue != null && !condition.isEmpty() && !conditionValue.isEmpty()) { if (condition != null && conditionValue != null && !condition.isEmpty() && !conditionValue.isEmpty()) {
where = " where "+ condition +" like '%" +conditionValue +"%'"; where = " where " + condition + " like '%" + conditionValue + "%'";
sql = sql+where; sql = sql + where;
} }
// 分页 // 分页
sql +=" order by id desc limit ?,?"; sql += " order by id desc limit ?,?";
pstmt = connection.prepareStatement(sql); pstmt = connection.prepareStatement(sql);
try { try {
pstmt.setInt(1, (Integer.parseInt(page)-1) * Integer.parseInt(limit) ); pstmt.setInt(1, (Integer.parseInt(page) - 1) * Integer.parseInt(limit));
pstmt.setInt(2, Integer.parseInt(limit)); pstmt.setInt(2, Integer.parseInt(limit));
} catch (NumberFormatException | SQLException e1) { } catch (NumberFormatException | SQLException e1) {
} }
resultSet = pstmt.executeQuery(); resultSet = pstmt.executeQuery();
while(resultSet.next()) { while (resultSet.next()) {
jsonObject.put("id", resultSet.getString("id")); jsonObject.put("id", resultSet.getString("id"));
jsonObject.put("password", resultSet.getString("password")); jsonObject.put("password", resultSet.getString("password"));
jsonObject.put("reader", resultSet.getString("reader")); jsonObject.put("reader", resultSet.getString("reader"));
@ -78,16 +77,16 @@ public class CardList extends HttpServlet {
// 获取总数 // 获取总数
sql = "select count(*) as count from borrow_card "; sql = "select count(*) as count from borrow_card ";
// 有限制 // 有限制
if(where!=null) { if (where != null) {
sql = sql+where; sql = sql + where;
} }
pstmt = connection.prepareStatement(sql); pstmt = connection.prepareStatement(sql);
resultSet = pstmt.executeQuery(); resultSet = pstmt.executeQuery();
if(resultSet.next()) { if (resultSet.next()) {
count = resultSet.getInt("count"); count = resultSet.getInt("count");
} }
if(!jsonArray.isEmpty()) { if (!jsonArray.isEmpty()) {
code = 0; code = 0;
msg = "成功"; msg = "成功";
} }
@ -96,7 +95,7 @@ public class CardList extends HttpServlet {
e.printStackTrace(); e.printStackTrace();
} catch (SQLException e) { } catch (SQLException e) {
msg = "sql错误"; msg = "sql错误";
}finally { } finally {
try { try {
Base.closeResource(connection, pstmt, resultSet); Base.closeResource(connection, pstmt, resultSet);
} catch (SQLException e) { } catch (SQLException e) {
@ -109,7 +108,7 @@ public class CardList extends HttpServlet {
jsonResult.put("data", jsonArray.toString()); jsonResult.put("data", jsonArray.toString());
PrintWriter out = resp.getWriter(); PrintWriter out = resp.getWriter();
out.print(jsonResult.toString()); out.print(jsonResult.toString());
//out.print("{\"code\":0,\"msg\":\"\",\"count\":\"234\",\"data\":[{\"id\":\"1\",\"password\":\"23442\",\"reader\":\"minm\",\"rule_id\":\"1\",\"status\":\"2\"}]}"); // out.print("{\"code\":0,\"msg\":\"\",\"count\":\"234\",\"data\":[{\"id\":\"1\",\"password\":\"23442\",\"reader\":\"minm\",\"rule_id\":\"1\",\"status\":\"2\"}]}");
} }
} }

@ -18,14 +18,13 @@ import javabean.Util;
import net.sf.json.JSONArray; import net.sf.json.JSONArray;
import net.sf.json.JSONObject; import net.sf.json.JSONObject;
@WebServlet("/admin/sortList") @WebServlet("/admin/sortList")
public class SortList extends HttpServlet { public class SortList extends HttpServlet {
@Override @Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.setContentType("application/json; charset:utf8"); resp.setContentType("application/json; charset=utf8");
// 接受参数 // 接受参数
// 准备参数 // 准备参数
Connection connection = null; Connection connection = null;
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
@ -44,16 +43,16 @@ public class SortList extends HttpServlet {
sql = "select * from book_sort"; sql = "select * from book_sort";
pstmt = connection.prepareStatement(sql); pstmt = connection.prepareStatement(sql);
resultSet = pstmt.executeQuery(); resultSet = pstmt.executeQuery();
while(resultSet.next()) { while (resultSet.next()) {
jsonObject.put("id", resultSet.getString("id")); jsonObject.put("id", resultSet.getString("id"));
jsonObject.put("name", resultSet.getString("name")); jsonObject.put("name", resultSet.getString("name"));
jsonObject.put("description", resultSet.getString("description")); jsonObject.put("description", resultSet.getString("description"));
jsonArray.add(jsonObject.toString()); jsonArray.add(jsonObject.toString());
} }
if(!jsonArray.isEmpty()) { if (!jsonArray.isEmpty()) {
code = 0; code = 0;
msg = "查询成功"; msg = "查询成功";
}else { } else {
msg = "数据为空"; msg = "数据为空";
} }
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
@ -61,15 +60,15 @@ public class SortList extends HttpServlet {
e.printStackTrace(); e.printStackTrace();
} catch (SQLException e) { } catch (SQLException e) {
msg = "sql错误"; msg = "sql错误";
}finally { } finally {
try { try {
Base.closeResource(connection, pstmt, resultSet); Base.closeResource(connection, pstmt, resultSet);
} catch (SQLException e) { } catch (SQLException e) {
msg = "关闭失败"; msg = "关闭失败";
} }
} }
out.print( Util.jsonResponse(code, msg, jsonArray.toString()) ); out.print(Util.jsonResponse(code, msg, jsonArray.toString()));
} }
} }

@ -47,7 +47,7 @@ public class Book extends HttpServlet {
String countSql = ""; String countSql = "";
// 准备返回参数 // 准备返回参数
int code = 1; int code = 1;
String msg = "error"; String msg = "无数据";
int count = 0; int count = 0;
JSONObject jsonData = new JSONObject(); JSONObject jsonData = new JSONObject();

@ -48,7 +48,7 @@ public class Borrow extends HttpServlet {
String countSql = ""; String countSql = "";
// 准备返回参数 // 准备返回参数
int code = 1; int code = 1;
String msg = "error"; String msg = "无数据";
int count = 0; int count = 0;
HttpSession session = req.getSession(); HttpSession session = req.getSession();

@ -48,7 +48,7 @@ public class Illegal extends HttpServlet {
String countSql = ""; String countSql = "";
// 准备返回参数 // 准备返回参数
int code = 1; int code = 1;
String msg = "error"; String msg = "无数据";
int count = 0; int count = 0;
HttpSession session = req.getSession(); HttpSession session = req.getSession();

Loading…
Cancel
Save