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); } }
详细解决方案
jsp学习札记(20)
热度:425 发布时间:2012-12-20 09:53:21.0
相关解决方案