📄 showbooksforgaojiservlet.java
字号:
package cn.dang.servlet;
import ghy_db.Conn_Manager;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import cn.dang.service.AllService;
public class ShowBooksForGaoJiServlet extends HttpServlet {
/**
* Constructor of the object.
*/
public ShowBooksForGaoJiServlet() {
super();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request
* the request send by the client to the server
* @param response
* the response send by the server to the client
* @throws ServletException
* if an error occurred
* @throws IOException
* if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.doPost(request, response);
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to
* post.
*
* @param request
* the request send by the client to the server
* @param response
* the response send by the server to the client
* @throws ServletException
* if an error occurred
* @throws IOException
* if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
/*
* String bookName=request.getParameter("bName").trim(); String
* authorName=request.getParameter("authorName").trim(); String
* concemName=request.getParameter("concemName").trim(); String
* dangPrice=request.getParameter("dangPrice").trim(); String
* dangPrice2=request.getParameter("dangPrice2").trim(); String
* publishTime=request.getParameter("publishTime").trim(); String
* overTime=request.getParameter("overTime").trim();
* System.out.println(concemName);
*/
AllService allService = new AllService();
String where_String = " ";
String String_start = "";
String String_over = "";
if (request.getParameter("bName") != null
&& !"".equals(request.getParameter("bName"))) {
where_String = "books.bookname like '%"
+ request.getParameter("bName") + "%' or ";
String_start = " and (";
String_over = " )";
}
if (request.getParameter("authorName") != null
&& !"".equals(request.getParameter("authorName"))) {
where_String += "author.authorname like '%"
+ request.getParameter("authorName") + "%' or ";
String_start = " and (";
String_over = " )";
}
if (request.getParameter("concemName") != null
&& !("".equals(request.getParameter("concemName")))) {
where_String += "bookconcem.concemname like'%"
+ request.getParameter("concemName") + "%' or ";
String_start = " and (";
String_over = " )";
}
if ((request.getParameter("dangPrice") != null && !"".equals(request
.getParameter("dangPrice")))
&& (request.getParameter("dangPrice2") != null && !""
.equals(request.getParameter("dangPrice2")))) {
where_String += "books.free between "
+ request.getParameter("dangPrice") + " and "
+ request.getParameter("dangPrice2") + " or ";
String_start = " and (";
String_over = " )";
}
if ((request.getParameter("publishTime") != null && !"".equals(request
.getParameter("publishTime")))
&& (request.getParameter("overTime") != null && !""
.equals(request.getParameter("overTime")))) {
where_String += "books.publishTime between '"
+ request.getParameter("publishTime") + " 00:00:00' and '"
+ request.getParameter("overTime") + " 23:59:59' or ";
String_start = " and (";
String_over = " )";
}
if (where_String != null && !"".equals(where_String.trim())) {
where_String = where_String.substring(0, where_String.length() - 3);
}
where_String = String_start + where_String + String_over;
System.out.println(where_String);
try {
String page = request.getParameter("page");
String type = request.getParameter("type");
HashMap hashMap = (HashMap) allService
.getBookService()
.list_shop(
"select books.bookname,books.price,books.price-books.free/10*books.price,author.authorname,bookconcem.concemname,books.publishtime,twotype.typename,books.pointgrade,author.authorname,books.bid,books.bcid,books.isbn,books.aid,books.tid",
"from books,author,bookconcem,twotype",
"where books.aid=author.aid and books.bcid=bookconcem.cid and books.tid=twotype.tid "
+ where_String, "", type, "books.tid",
"books.bid", page, 5, true);
request.setAttribute("listBooks", hashMap.get("listBooks"));
request.setAttribute("pagebean", hashMap.get("pagebean"));
request.setAttribute("typeList", hashMap.get("TypeList"));
request.setAttribute("statusAll", "have");
Conn_Manager.transaction_commit();
request.getRequestDispatcher(
"../manager/rightShowBooks.jsp?page=" + page + "&type="
+ type).forward(request, response);
} catch (Throwable e) {
// TODO Auto-generated catch block
Conn_Manager.transaction_rollback();
e.printStackTrace();
}
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException
* if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -