网上书城论文 - 图文

2026/1/27 16:28:36

第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 pb = bookService.findByAuthor(author, pc); /*

* 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 pb = bookService.findByPress(press, pc); /*

* 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 pb = bookService.findByBname(bname, pc); /*

* 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


网上书城论文 - 图文.doc 将本文的Word文档下载到电脑
搜索更多关于: 网上书城论文 - 图文 的文档
相关推荐
相关阅读
× 游客快捷下载通道(下载后可以自由复制和排版)

下载本文档需要支付 10

支付方式:

开通VIP包月会员 特价:29元/月

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:xuecool-com QQ:370150219