软件需求与分析
1今日完成网络审核
2、明日目标多条件查询
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> <!-- Bootstrap --> <link href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" rel="stylesheet"> <script src="https://cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js"></script> <!-- 加载 Bootstrap 的所有 JavaScript 插件。你也可以根据需要只加载单个插件。 --> <script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js"></script> </head> <body> <div class="container-fluid"> <div class="row-fluid"> <div class="span6"> <div class="row-fluid"> <div class="span4"> <form class="form-search" action="checkque"> <table><tr><td><input class="input-medium search-query" type="text" placeholder="机构全称" name="jigoumingcheng"></td> <td><input class="input-medium search-query" type="text" placeholder="所在地域" name="province"></td> <td><input class="input-medium search-query" type="text" placeholder="技术需求名称" name="Name"></td> <td><input class="input-medium search-query" type="text" placeholder="归口管理单位" name="guikou"></td> <td><input class="input-medium search-query" type="text" placeholder="机构属性" name="shuxing"></td> <td><input class="input-medium search-query" type="text" placeholder="科技活动类型" name="duoxuan"></td> <td><button class="btn" type="submit">查找</button></td></tr></table> </form> </div> </div> </div> <div class="row-fluid"> <div class="span12"> <table class="table table-bordered table-hover"> <thead> <tr> <th> 编号 </th> <th> 机构全称 </th> <th> 技术需求名称 </th> <th> 所在地域 </th> <th> 归口管理单位 </th> <th> 机构属性 </th> <th> 法人代表 </th> <th> 拟投入资金金额 </th> <th> 科技活动类型 </th> </tr> </thead> <tbody> <c:forEach var="item" items="${list}" varStatus="i"> <tr class="info"> <td> <a href="selectid?id=${item.id }">${item.id}</a> </td> <td> ${item.jigoumingcheng } </td> <td> ${item.name } </td> <td> ${item.province } </td> <td> ${item.guikou } </td> <td> ${item.shuxing } </td> <td> ${item.faren } </td> <td> ${item.nitouru } </td> <td> ${item.duoxuan } </td> </tr></c:forEach> </tbody> </table> </div> </div> </div> </body> </html>
servlet
package servlet; import java.io.IOException; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.ArrayList; import java.util.List; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import Bean.Gongwen; import DBUtil.DBUtil; /** * Servlet implementation class checkque */ @WebServlet("/checkque") public class checkque extends HttpServlet { private static final long serialVersionUID = 1L; /** * @see HttpServlet#HttpServlet() */ public checkque() { super(); // TODO Auto-generated constructor stub } /** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub String jigou=request.getParameter("jigoumingcheng"); String province=request.getParameter("province"); String Name=request.getParameter("Name"); String guikou=request.getParameter("guikou"); String shuxing=request.getParameter("shuxing"); String duoxuan=request.getParameter("duoxuan"); StringBuilder sql1=new StringBuilder("select * from xvqiu where 1 and 1"); if(jigou!=null&&!jigou.trim().isEmpty()) { sql1.append(" and jigoumingcheng like '%"+jigou+"%'"); } else if(province!=null&&!province.trim().isEmpty()) { sql1.append(" and province like '%"+province+"%'"); } else if(Name!=null&&!Name.trim().isEmpty()) { sql1.append(" and Name like '%"+Name+"%'"); } else if(guikou!=null&&!guikou.trim().isEmpty()) { sql1.append(" and guikou like '%"+guikou+"%'"); } else if(shuxing!=null&&!shuxing.trim().isEmpty()) { sql1.append(" and shuxing like '%"+shuxing+"%'"); } else if(duoxuan!=null&&!duoxuan.trim().isEmpty()) { sql1.append(" and duoxuan like '%"+duoxuan+"%'"); } String sql=sql1.toString(); System.out.println(sql); List<Gongwen>list=new ArrayList<Gongwen>(); Connection conn = DBUtil.getConn(); Statement state = null; ResultSet rs = null; boolean flag=false; Gongwen gongwen=null; try { state = conn.createStatement(); rs = state.executeQuery(sql); //要用statement类的executeQuery()方法来下达select指令以查询数据库, //executeQuery()方法会把数据库响应的查询结果存放在ResultSet类对象中供我们使用。 while (rs.next()) { int id=rs.getInt("id"); String jigou1=rs.getString("jigoumingcheng"); String shuxing1=rs.getString("shuxing"); String Name1=rs.getString("Name"); String province1=rs.getString("province"); String faren=rs.getString("faren"); String guikou1=rs.getString("guikou"); String nitouru=rs.getString("nitouru"); String duoxuan1=rs.getString("duoxuan"); gongwen=new Gongwen(id,jigou1,guikou1,province1,faren,shuxing1,Name1,nitouru,duoxuan1); list.add(gongwen); flag = true; } } catch (SQLException e) { e.printStackTrace(); } finally { DBUtil.close(rs, state, conn); } request.setAttribute("list",list); request.getRequestDispatcher("templete/wlsh.jsp").forward(request, response); } /** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub doGet(request, response); } }