搜索功能

搜索功能(模糊搜索)

1.搜索功能介绍

只要在搜索栏里输入少许关键字,只要主题里有含有的,都会显示出来

2.功能截图

搜索功能_第1张图片

search的代码(实现查询功能):

 <body>
    <form action="dealing/searchresponse.jsp" method="get" target="middlemain">
    <br>
     Search:<input type="text" name="name" size="60"><input type="submit" class="searchsubmit" value="   " >
    </form>
  </body>

  查询显示的代码:

  <body>
  
        <%
          String name=new String(request.getParameter("name").getBytes("ISO-8859-1"),"UTF-8");         
          Connection con=null;
          Statement stmt=null;
          ResultSet rs=null;
          String author;
          String topic;
          String classify;
          int i=0;
          Class.forName("com.mysql.jdbc.Driver");
          String url="jdbc:mysql://localhost:3306/learning?useUnicode=true&characterEncoding=gbk";
          con=DriverManager.getConnection(url,"root","root");
          stmt=con.createStatement();
          String query="select * from showframe where topic like '%"+name+"%' ";
          rs=stmt.executeQuery(query);
          %>
    <table align="center" width="100%" border="1">
        <tr background="#22dcff" >
            <th>类型</th>
            <th>类型</th>
            <th>作者</th>
            <th>主题</th>
            <th>回复</th>
            <th>收藏</th>
        </tr>
          <%
          while(rs.next()){  
          author=rs.getString("author");
          topic=rs.getString("topic");  
          classify=rs.getString("classify");
          i++;
           %>
          <tr height="40" >
              <td align="center"><%=i%></td>
              <td ><%=rs.getString("classify") %></td>
              <td><%=author%></td>
              <td><a href="dealing/response.jsp?author=<%=author%>&topic=<%=topic%>"><%=topic%></a></td>
              <td align="center"><%=rs.getString("total") %></td>
              <td align="center"><a href="dealing/shoucang.jsp?classify=<%=classify %>&author=<%=author%>&topic=<%=topic%>">收藏</a></td>     
          </tr>
          <%
            }
           %>
     </table>
  </body>

  

你可能感兴趣的:(搜索)