第5章 系统实现
/*
* 获取请求的url,但去除pc参数 */
private String getUrl(HttpServletRequest req) { }
String url = req.getRequestURI() + \ + req.getQueryString(); int fromIndex = url.lastIndexOf(\); if(fromIndex == -1) return url;
int toIndex = url.indexOf(\, fromIndex + 1); if(toIndex == -1) return url.substring(0, fromIndex); return url.substring(0, fromIndex) + url.substring(toIndex);
可以在图书列表上方输入关键字进行搜索。 点击某本图书,会到达图书详细页面。
图5-6 图书详细信息页面
在图书列表页面点击高级搜索到达搜索页面。
图5-7 高级搜索页面
31
第5章 系统实现
高级搜索有三个条件:书名、作者、出版社,三个条件的关系是并列的。而且三个条件都是模糊查询。 相关代码:
/** * 按作者查询 * @param request * @param response * @return
* @throws ServletException * @throws IOException */
public String findByAuthor(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
/*
* 1. 获取当前页码 */
int pc = getPageCode(request); /*
* 2. 使用BookService查询,得到PageBean */
String author = request.getParameter(\);
PageBean
* 3. 获取url,设置给PageBean */
String url = getUrl(request); pb.setUrl(url); /*
* 4. 把PageBean保存到request,转发到/jsps/book/list.jsp */
request.setAttribute(\, pb); return \;
}
32
第5章 系统实现
/**
* 按出版社查询 * @param request * @param response * @return
* @throws ServletException * @throws IOException */
public String findByPress(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
/*
* 1. 获取当前页码 */
int pc = getPageCode(request); /*
* 2. 使用BookService查询,得到PageBean */
String press = request.getParameter(\);
PageBean
* 3. 获取url,设置给PageBean */
String url = getUrl(request); pb.setUrl(url); /*
* 4. 把PageBean保存到request,转发到/jsps/book/list.jsp */
request.setAttribute(\, pb); return \;
}
/**
* 按图名查询
33
第5章 系统实现
* @param request * @param response * @return
* @throws ServletException * @throws IOException */
public String findByBname(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
/*
* 1. 获取当前页码 */
int pc = getPageCode(request); /*
* 2. 使用BookService查询,得到PageBean */
String bname = request.getParameter(\);
PageBean
* 3. 获取url,设置给PageBean */
String url = getUrl(request); pb.setUrl(url); /*
* 4. 把PageBean保存到request,转发到/jsps/book/list.jsp */
request.setAttribute(\, pb); return \;
}
/** * 加载图书 * @param request
* @param response
34

