search.jsp~36~
上传用户:top0756
上传日期:2022-08-11
资源大小:6501k
文件大小:3k
源码类别:

Jsp/Servlet

开发平台:

VBScript

  1. <%@page contentType="text/html;charset=gb2312"%>
  2. <%@page import="java.sql.*"%><head>
  3.   <SCRIPT language="JavaScript">
  4. function a() {
  5. if(form1.keywords.value==""){
  6. alert("用户名不能为空,请确定后重新输入");
  7. form1.keywords.focus();
  8. return false;
  9. }
  10. return true;
  11. }</script></head>
  12. <HTML><BODY >
  13. <br>
  14. <%
  15. Connection conn = null;
  16. Statement stmt = null;
  17. ResultSet rs = null;
  18. try{
  19. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  20. }
  21. catch(ClassNotFoundException ce){
  22. out.println(ce.getMessage());
  23. }
  24. request.setCharacterEncoding("GBK");
  25. String str = request.getParameter("keywords");
  26. if( str == null)
  27. str = "";
  28.       else
  29. try{
  30. conn=DriverManager.getConnection("jdbc:odbc:dsn112");
  31. stmt=conn.createStatement();
  32.         rs=stmt.executeQuery("SELECT * FROM student WHERE stu_id LIKE '%" + str + "%'");
  33.         out.print("<table  width='100%' cellspacing='0' cellpadding='4' rules='all' bordercolor='#CC9966' border='1' id='dg_rxkb' style='background-color:White;border-color:#CC9966;border-width:1px;border-style:None;width:99%;border-collapse:collapse;'>");
  34.          out.print("<tr bgcolor='EcEcff' align='center'><TD>姓名</TD>");
  35. out.print("<TD>性别</TD>");
  36. out.print("<TD>年龄</TD>");
  37. out.print("<TD>专业</TD>");
  38.                 out.print("<TD>入学时间</TD>");
  39.                 out.print("<TD>联系方式</TD>");
  40.        out.print("<TD>地址</TD></TR>");
  41. while(rs.next()){
  42. out.print("<tr align='center'><TD>"+rs.getString("name")+"</TD>");
  43. out.print("<TD>"+rs.getString("sex")+"</TD>");
  44. out.print("<TD>"+rs.getString("age")+"</TD>");
  45. out.print("<TD>"+rs.getString("dept")+"</TD>");
  46.                 out.print("<TD>"+rs.getString("ruxdate")+"</TD>");
  47.                  out.print("<TD>"+rs.getString("tel")+"</TD>");
  48. out.print("<TD>"+rs.getString("address")+"</TD></TR>");
  49. }
  50. out.print("</TABLE>");
  51. }
  52. catch(SQLException e){
  53. System.out.println(e.getMessage());
  54. }
  55. finally{
  56. stmt.close();
  57. conn.close();
  58. }
  59. %>
  60. <br><br>
  61.  <FORM  name="form1" Action="search.jsp" Method="POST">
  62.  <table  width="100%" cellspacing="0" cellpadding="4" rules="all" bordercolor="#CC9966" border="1" id="dg_rxkb" style="background-color:White;border-color:#CC9966;border-width:1px;border-style:None;width:99%;border-collapse:collapse;">
  63. <tr>
  64.       <td   colspan="2"><div align="center" ><font  size="5" color="red">查找信息</strong></font></div></td>
  65.     </tr>
  66. <tr ><td><font color="000000" size="4">输入姓名关键字:</td>
  67. <td><INPUT Type="Text" Name="keywords" Value="<%=str%>"></td></tr>
  68. <tr><td  height="35" colspan="2"><div align="center"><INPUT Type=Submit Value=" 查找" onClick="return a()"></td></tr></table>
  69. </FORM>
  70. <br>
  71. <br>
  72. <br>
  73. <p align=center>
  74. <img src="img/boshi.jpg">
  75. </BODY></HTML>