日期:2014-05-16  浏览次数:20389 次

jsp学习笔记(20)
SearchServlet代码如下:
	package servlet.user;
	import java.io.IOException;
	import javax.servlet.RequestDispatcher;
	import javax.servlet.ServletException;
	import javax.servlet.http.HttpServlet;
	import javax.servlet.http.HttpServletRequest;
	import javax.servlet.http.HttpServletResponse;
	import dao.DBOperation;
	import util.Validate;
	public class SearchServlet extends HttpServlet {
		public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
			Validate vd = new Validate();
			String name = vd.getUnicode(request.getParameter(“name”));
			String bookl = vd.getUnicode(request.getParameter(“bookl”));
			String types = vd.getUnicode(request.getParameter(“types”));
			DBOperation dbo=new DBOperation();
			String sql = “select * from books “;
			if (name != null && !name.equals(“”)) {
				sql += “where name like ‘%” + name + “%’”;
			}
			if (bookl != null && !cuban.equals(“”)) {
				sql += “where publishing like ‘%” + bookl + “%’”;
			}
			if (types != null && !types.equals(“”)) {
				sql += “where type=’” + types + “’”;
			}
			request.setAttribute(“search”, dbo.queryReturnList(sql));
			RequestDispatcher rd = request.getRequestDispatcher(“/user/booklist.jsp”);
			rd.forward(request, response);
		}
		public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
			doGet(request, response);
		}
	}