打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
jsp中模糊查询

<%@ page contentType="text/html;charset=gb2312" %>
<%@ page language="java" import="java.sql.*"%>
<jsp:useBean id="connc" scope="page" class="db.ConnOracle"/>
<%
String sql = "";
String key = "";
String type= "";
String sortfield = "";
%>
<%
request.setCharacterEncoding("gb2312");
sql = "select * from student";
key = request.getParameter("mkey");
System.out.print(key);
type = request.getParameter("mtype");
sortfield = request.getParameter("sortfield");
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">

 <title>test db connection</title>
</head>
<body bgcolor="#FFFFFF">
<div align="center">
<form action="d_sql2.jsp" method="post">
    查询关键字:<Input type="text" name="mkey">   
 请选择查找操作字段:
 <select name="mtype">
  <option value="studentid">studentid</option>
  <option value="studentname">studentname</option>
  <option value="gender">gender</option>
  <option value="phone">phone</option>
 </select>   
 <Input type="submit" value="查看">
</form>
<hr>
  <table width="60%" border="1">
    <tr bgcolor="#CCCCFF">
      <td width="25%">
        <div align="center"><font color="#FF0033"><b>
    <a href="d_sql2.jsp?mkey=<%=key%>&mtype=<%=type%>&studentid">学号</a>
  </b></font></div>
      </td>
      <td width="25%">
        <div align="center"><font color="#FF0033"><b>
    <a href="d_sql2.jsp?mkey=<%=key%>&mtype=<%=type%>&studentname">姓名</a>
  </b></font></div>
      </td>
      <td width="25%">
        <div align="center"><font color="#FF0033"><b>
    <a href="d_sql2.jsp?mkey=<%=key%>&mtype=<%=type%>&sortfield=gender">性别</a>
  </b></font></div>
      </td>
      <td width="25%">
        <div align="center"><font color="#FF0033"><b>
    <a href="d_sql2.jsp?mkey=<%=key%>&m-type=<%=type%>&sortfield=phone">电话</a>
  </b></font></div>
      </td>
    </tr>
<%
if(key != null && !key.equals("") && type != null && !type.equals(""))
    sql += " where " + type + " like '%" + key + "%' ";
if(sortfield != null && !sortfield.equals("")) 
 sql += " order by " + sortfield ;

ResultSet RS_result = connc.executeQuery( sql );
String studentName="";
String studentSex="";
String studentScore="";
String phone="";
while(RS_result.next())
{
studentName = RS_result.getString("studentid");
studentSex = RS_result.getString("studentname");
studentScore = RS_result.getString("gender");
phone=RS_result.getString("phone");
%>
    <tr>
      <td width="25%" bgcolor="#FFFFFF">
        <div align="center"><%=studentName%></div>
      </td>
      <td width="25%">
        <div align="center"><%=studentSex%></div>
      </td>
      <td width="25%">
       <div align="center"><%=studentScore%></div>
      </td>
 <td width="25%">
       <div align="center"><%=phone%></div>
      </td>
    </tr>
<%
}
RS_result.close();
%>
  </table>
</div>
</body>
</html>

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
JSP连接SQL数据库实现查找/插入信息
jsp购物车源码①
STORM--站长笔记
Jsp分页实例代码
贴个Flex-Jsp-Mysql简单结合例子
利用javabean进行分页技术----(与同学开发的小招标系统项目节选)_Java风影园地
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服