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="java.sql.PreparedStatement"%>
<%@page import="com.mysql.jdbc.Connection"%>
<%@page import="java.sql.Connection"%>
<%@page import="javabean.Base"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="javabean.JDBCBean"%>

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

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

@ -2,6 +2,7 @@ package servlet.admin;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
@ -12,8 +13,6 @@ import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.sql.Connection;
import javabean.Base;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
@ -25,19 +24,19 @@ import net.sf.json.JSONObject;
public class CardList extends HttpServlet {
@Override
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 page = req.getParameter("page");
String condition = (String) req.getParameter("condition");
String conditionValue = (String) req.getParameter("conditionValue");
String where = null; // 无限制条件
if(page == null) {
page = "1";
}
if(limit == null) {
limit = "10";
}
String condition = (String) req.getParameter("condition");
String conditionValue = (String) req.getParameter("conditionValue");
String where = null; // 无限制条件
if (page == null) {
page = "1";
}
if (limit == null) {
limit = "10";
}
Connection connection = null;
PreparedStatement pstmt = null;
ResultSet resultSet = null;
@ -45,7 +44,7 @@ public class CardList extends HttpServlet {
String msg = "error";
int count = 0;
String sql = "";
//String countSql = ""
// String countSql = ""
JSONObject jsonObject = new JSONObject();
JSONArray jsonArray = new JSONArray();
JSONObject jsonResult = new JSONObject();
@ -54,20 +53,20 @@ public class CardList extends HttpServlet {
connection = (Connection) Base.getConnection();
sql = "select id,password,reader,rule_id,status from borrow_card";
// where
if(condition != null && conditionValue != null && !condition.isEmpty() && !conditionValue.isEmpty()) {
where = " where "+ condition +" like '%" +conditionValue +"%'";
sql = sql+where;
}
if (condition != null && conditionValue != null && !condition.isEmpty() && !conditionValue.isEmpty()) {
where = " where " + condition + " like '%" + conditionValue + "%'";
sql = sql + where;
}
// 分页
sql +=" order by id desc limit ?,?";
sql += " order by id desc limit ?,?";
pstmt = connection.prepareStatement(sql);
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));
} catch (NumberFormatException | SQLException e1) {
}
resultSet = pstmt.executeQuery();
while(resultSet.next()) {
while (resultSet.next()) {
jsonObject.put("id", resultSet.getString("id"));
jsonObject.put("password", resultSet.getString("password"));
jsonObject.put("reader", resultSet.getString("reader"));
@ -78,16 +77,16 @@ public class CardList extends HttpServlet {
// 获取总数
sql = "select count(*) as count from borrow_card ";
// 有限制
if(where!=null) {
sql = sql+where;
if (where != null) {
sql = sql + where;
}
pstmt = connection.prepareStatement(sql);
resultSet = pstmt.executeQuery();
if(resultSet.next()) {
if (resultSet.next()) {
count = resultSet.getInt("count");
}
if(!jsonArray.isEmpty()) {
if (!jsonArray.isEmpty()) {
code = 0;
msg = "成功";
}
@ -96,7 +95,7 @@ public class CardList extends HttpServlet {
e.printStackTrace();
} catch (SQLException e) {
msg = "sql错误";
}finally {
} finally {
try {
Base.closeResource(connection, pstmt, resultSet);
} catch (SQLException e) {
@ -109,7 +108,7 @@ public class CardList extends HttpServlet {
jsonResult.put("data", jsonArray.toString());
PrintWriter out = resp.getWriter();
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.JSONObject;
@WebServlet("/admin/sortList")
public class SortList extends HttpServlet {
@Override
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;
PreparedStatement pstmt = null;
@ -44,16 +43,16 @@ public class SortList extends HttpServlet {
sql = "select * from book_sort";
pstmt = connection.prepareStatement(sql);
resultSet = pstmt.executeQuery();
while(resultSet.next()) {
while (resultSet.next()) {
jsonObject.put("id", resultSet.getString("id"));
jsonObject.put("name", resultSet.getString("name"));
jsonObject.put("description", resultSet.getString("description"));
jsonArray.add(jsonObject.toString());
}
if(!jsonArray.isEmpty()) {
if (!jsonArray.isEmpty()) {
code = 0;
msg = "查询成功";
}else {
msg = "查询成功";
} else {
msg = "数据为空";
}
} catch (ClassNotFoundException e) {
@ -61,15 +60,15 @@ public class SortList extends HttpServlet {
e.printStackTrace();
} catch (SQLException e) {
msg = "sql错误";
}finally {
} finally {
try {
Base.closeResource(connection, pstmt, resultSet);
} catch (SQLException e) {
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 = "";
// 准备返回参数
int code = 1;
String msg = "error";
String msg = "无数据";
int count = 0;
JSONObject jsonData = new JSONObject();

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

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

Loading…
Cancel
Save