⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 searchbookservlet.java

📁 网上书店 源代码和数据库网上书店 源代码和数据库
💻 JAVA
字号:
package com.shop.controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.shop.model.dao.BookInfoDAO;
import com.shop.vo.BookInfoVo;

public class SearchBookServlet extends HttpServlet {

	/**
	 * 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 {

		String iisbn=request.getParameter("iisbn");
		BookInfoVo book2=new BookInfoVo();
		BookInfoDAO bookdao=new BookInfoDAO();
		//List<BookInfoVo> bookList2=null;
		book2=bookdao.findBookByName(iisbn);
		request.setAttribute("book2", book2);
		request.getRequestDispatcher("/booksearch/bookinfo.jsp").forward(request, response);
	}

	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		BookInfoVo book=new BookInfoVo();
		String isbnStr,nameStr,authorStr,pubStr;
		String isbn=request.getParameter("isbn");
		int counter=0;
		if(!isbn.equals("")){
			isbnStr=" ISBN='"+isbn+"' and ";
			counter++;
		}else{
			isbnStr="";
		}
		String bookname=request.getParameter("bookname");
		if(!bookname.equals("")){
			nameStr=" BOOKNUM='"+bookname+"' and ";
			counter++;
		}else{
			nameStr="";
		}
		String author=request.getParameter("author");
		if(!author.equals("")){
			authorStr=" AUTHOR='"+author+"' and ";
			counter++;
		}else{
			authorStr="";
		}
		String publisher=request.getParameter("publisher");
		if(!publisher.equals("")){
			pubStr=" PRINTADDRESS='"+publisher+"' and ";
			counter++;
		}else{
			pubStr="";
		}
		if(counter==0){
			request.getRequestDispatcher("/booksearch/searchBook.jsp?select=faile").forward(request, response);
			return;
		}
		String sql=isbnStr+nameStr+authorStr+pubStr+" 1=1";
		System.out.println(sql);
		BookInfoDAO bookdao=new BookInfoDAO();
		List<BookInfoVo> bookList=null;
		bookList=bookdao.findBookVO(sql);
		request.setAttribute("isbn", isbn);
		request.setAttribute("author", author);
		request.setAttribute("printNum", bookname);
		request.setAttribute("publisher", publisher);
		request.setAttribute("booklist", bookList);
		request.getRequestDispatcher("/booksearch/searchResult.jsp").forward(request, response);
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -