404,莫名解决了,好像是因为直接启动了servlet没有的get方法?添加了filter的init方法,错误点在adminFilter

pull/1/head
you 5 years ago
parent 92493895b3
commit 3d73112b51

Binary file not shown.

@ -20,6 +20,10 @@ import javax.servlet.http.HttpSession;
*/ */
public class AdminFilter implements Filter { public class AdminFilter implements Filter {
public void init(FilterConfig filterConfig) throws ServletException {
}
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
HttpServletRequest req = (HttpServletRequest) request; HttpServletRequest req = (HttpServletRequest) request;
HttpSession session = req.getSession(); HttpSession session = req.getSession();

@ -27,54 +27,52 @@ public class BookList 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");
JSONObject json = new JSONObject(); JSONObject json = new JSONObject();
String result = null; String result = null;
Map<String, Object> map = null; Map<String, Object> map = null;
int code = 1; int code = 1;
String msg = ""; String msg = "";
String data = ""; String data = "";
String page = (String) req.getParameter("page"); String page = (String) req.getParameter("page");
String limit = (String) req.getParameter("limit"); String limit = (String) req.getParameter("limit");
String condition = (String) req.getParameter("condition"); String condition = (String) req.getParameter("condition");
String conditionValue = (String) req.getParameter("conditionValue"); String conditionValue = (String) req.getParameter("conditionValue");
Map where = new HashMap<String, String>(); Map where = new HashMap<String, String>();
//System.out.println(condition +"" +conditionValue); // 传输数据过滤
// 传输数据过滤 if(page == null) {
if(page == null) { page = "1";
page = "1"; }
} if(limit == null) {
if(limit == null) { limit = "10";
limit = "10"; }
} if(condition == null || conditionValue == null || condition.isEmpty() || conditionValue.isEmpty()) {
if(condition == null || conditionValue == null || condition.isEmpty() || conditionValue.isEmpty()) { condition = null;
condition = null; conditionValue = null;
conditionValue = null; }else {
}else { where.put("condition", condition);
where.put("condition", condition); where.put("conditionValue", conditionValue);
where.put("conditionValue", conditionValue); }
} Admin admin = new Admin();
Admin admin = new Admin(); try {
try {
map = admin.getBookList(page, limit, where); map = admin.getBookList(page, limit, where);
result = (String) map.get("data"); result = (String) map.get("data");
} catch (ClassNotFoundException | SQLException e) { } catch (ClassNotFoundException | SQLException e) {
msg = "数据库获取信息失败"; msg = "数据库获取信息失败";
} }
if(result == null || result.isEmpty() || result.equals("1")) { if(result == null || result.isEmpty() || result.equals("1")) {
json.put("code", 1); json.put("code", 1);
json.put("msg", "数据为空"); json.put("msg", "数据为空");
} else { } else {
json.put("code", 0); json.put("code", 0);
json.put("msg", "success"); json.put("msg", "success");
json.put("count", map.get("count")); json.put("count", map.get("count"));
result = "[" +result +"]"; result = "[" +result +"]";
json.put("data", result); json.put("data", result);
} }
PrintWriter out = resp.getWriter(); PrintWriter out = resp.getWriter();
out.print(json.toString()); out.print(json.toString());
//out.print("{\"code\":0,\"msg\":\"\",\"count\":10,\"data\":[{\"id\":10000,\"name\":\"夏洛特的烦恼\",\"library_name\":\"南图\",\"sort_id\":\"言情\",\"position_id\":\"sdf\",\"state\":\"借出\",\"descript\":\"好看\",\"operate\":\"234\"},{\"id\":10000,\"name\":\"夏洛特的烦恼\",\"library_name\":\"南图\",\"sort_id\":\"言情\",\"position_id\":\"sdf\",\"state\":\"借出\",\"descript\":\"好看\",\"operate\":\"234\"},{\"id\":10000,\"name\":\"夏洛特的烦恼\",\"library_name\":\"南图\",\"sort_id\":\"言情\",\"position_id\":\"sdf\",\"state\":\"借出\",\"descript\":\"好看\",\"operate\":\"234\"},{\"id\":10010,\"name\":\"夏洛特的烦恼\",\"library_name\":\"南图\",\"sort_id\":\"言情\",\"position_id\":\"sdf\",\"state\":\"借出\",\"descript\":\"好看\",\"operate\":\"234\"}]}");
} }
@Override @Override

Loading…
Cancel
Save