wuhongze的专栏

没有生命的鱼--- 态度决定命运,可以不会但不能不去努力

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">&nbsp;&nbsp;&nbsp;
 请选择查找操作字段:
 <select name="mtype">
  <option value="studentid">studentid</option>
  <option value="studentname">studentname</option>
  <option value="gender">gender</option>
  <option value="phone">phone</option>
 </select>&nbsp;&nbsp;&nbsp;
 <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>
值得体会

阅读更多
个人分类: JAVA专栏
上一篇权限登陆演示
下一篇java面试
想对作者说点什么? 我来说一句

完整JSP模糊查询

2014年02月22日 1.29MB 下载

jsp模糊查询并分页

2013年04月17日 5KB 下载

没有更多推荐了,返回首页

关闭
关闭