jsp--学生信息管理系统

grade
学号姓名语文数学英语
1001王九0880
4004
000
4004
000
1张敏111
1张三100100100
11100100100
90038张三1001001100
14周星驰5010080
15周惠敏5001301000
16张敏600130200
17丘淑贞4501301200
18舒淇10002030800
20刘德华20010302000
22比尔_盖茨400050301000
23小布什500530500
24毛宁100130100
25扬玉莹200230200
26巩俐1005301000
27李小龙10010301000
28成龙200010304000
29李连杰250150120
30周华键260660560
31赵微3401230450
index.jsp:

<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
<%@ page import="java.sql.*" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    <title>My JSP 'index.jsp' starting page</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
  </head>
  <script type="text/javascript">
  function del(){
  var msg = "您真的确定要删除吗?\n\n请确认!"; 
  if (confirm(msg)==true){ return true; }
  else{ return false; } 
  }
  </script>
  <body>
    <%
    Connection conn;
    Statement stmt;
    ResultSet rs;
    int Page=1;//当前页数 
    int totalpage=0;//总页数
    int totalrecord=0;//总条数 
    String sql="select * from grade";
   String sql1="select count(*) as gradeno from grade";
    try{
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    }
    catch(ClassNotFoundException e){
    System.out.print(e);
    }
    try{
    conn=DriverManager.getConnection("jdbc:odbc:1");
    stmt=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
    rs=stmt.executeQuery(sql1);
    rs.next();
    totalrecord=rs.getInt(1);
    if(totalrecord%5==0){
    totalpage=totalrecord/5;
    }
    else{
    totalpage=totalrecord/5+1;
    }
    rs=stmt.executeQuery(sql);
    if(request.getParameter("Page")==null||request.getParameter("Page").equals("")){
      Page=1;
    }
    else{
    try{
    Page=Integer.parseInt(request.getParameter("Page"));
    }
    catch(java.lang.NumberFormatException e){
    Page=1;
    }
    }
    if(Page>totalpage){
    Page=totalpage;
    }
    if(Page<1){
    Page=1;
    }
    out.print("<table border=1 width=500 align=center>");
    rs.absolute((Page-1)*5+1);
    for(int i=0;i<5;i++){
    String a=rs.getString(1);
    out.print("<tr><td><a href=view.jsp?id="+a+">"+a+"</a></td>");
    out.print("<td>"+rs.getString(2)+"</td>");
    out.print("<td>"+rs.getString(3)+"</td>");
    out.print("<td>"+rs.getString(4)+"</td>");
    out.print("<td>"+rs.getString(5)+"</td>");
    out.print("<td><a href=modify.jsp?id="+a+">修改</a></td>");
    out.print("<td><a href=delete.jsp?id="+a+" onClick='javascript:return del();'>删除</a></td></tr>");
    if(!rs.next()) break;
    }
   out.print("<tr><td><a href=index.jsp>第一页</a></td>");
   out.print("<td><a href=index.jsp?Page="+(Page-1)+">上一页</a></td>");
   out.print("<td><a href=index.jsp?Page="+(Page+1)+">下一页</a></td>"); 
   out.print("<td><a href=index.jsp?Page="+totalpage+">最后一页</a></td></tr>");
   conn.close();
    }
    catch(SQLException e){System.out.print(e);}
     %>
     <form action="index.jsp" method="post">
     当前页:<%=Page%>|<%=totalpage%> 请输入页数:<input type="text" size=2 name="Page"><input type="submit" value="go">
  </form>
  </body>
</html>
modify.jsp:
<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
<%@ page import="java.sql.*" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'modify.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <body>
   <%
   String id=request.getParameter("id");
   String name="";
   String yw=null;
    String sx=null;
    String yy=null;
   
  // out.print(id);
  String sql="select * from grade where 学号="+id;
   //out.print(sql);

    Connection conn;
    Statement stmt;
    ResultSet rs;
     try{
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    }
    catch(ClassNotFoundException e){
    System.out.print(e);
    }
    try{
    
    conn=DriverManager.getConnection("jdbc:odbc:1");
    stmt=conn.createStatement();
    rs=stmt.executeQuery(sql);
    rs.next();
    name=rs.getString(2);
    yw=rs.getString(3);
     sx=rs.getString(4);
     yy=rs.getString(5);
    //out.print(name+yw+sx+yy);
    conn.close();}
    catch(SQLException e){
     System.out.print(e);
    
    }
    %>
    <form action="save.jsp">
    请修改学号:<input type="text" name="id" value="<%=id %>" readonly/><br/>
    请修改姓名:<input type="text" name="name" value="<%=name%>"/><br/>
    请修改语文成绩:<input type="text" name="yw" value="<%=yw %>"/><br/>
   请修改数学成绩:<input type="text" name="sx" value="<%=sx %>"/><br/> 
  请修改英语成绩:<input type="text" name="yy" value="<%=yy %>"/><br/>  
   <input type="submit" value="修改">
    </form>
  </body>
</html>

delete.jsp:
<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
<%@ page import="java.sql.*" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'delete.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <body>
    <%
    Connection conn;
    Statement stmt;
    String id=request.getParameter("id");
    
    String sql="delete from grade where 学号="+id;
    
    try{
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    }
    catch(ClassNotFoundException e){
    System.out.print(e);
    }
    try{
    conn=DriverManager.getConnection("jdbc:odbc:1");
    stmt=conn.createStatement();
    int i=stmt.executeUpdate(sql);
    out.print("成功删除"+i+"条记录");
    conn.close();
    }
    catch(SQLException e){
     System.out.print(e);
    }
     %>
  </body>
</html>

option.jsp:

<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
<%@ page import="java.sql.*" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'index.jsp' starting page</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
  </head>
  
  <body>
    <%
    Connection conn;
    Statement stmt;
    ResultSet rs;
    int n=0;
    String a[]=null;
    String sql="select count(*) from book";
    String sql1="select * from book";
     
     Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
     
     try{
     conn=DriverManager.getConnection("jdbc:odbc:1");
     stmt=conn.createStatement();
     rs=stmt.executeQuery(sql);
     rs.next();
     n=rs.getInt(1);
    // out.print(n);
     a=new String[n];
     rs=stmt.executeQuery(sql1);
     for(int i=0;i<n;i++){
     rs.next();
     a[i]=rs.getString(3);
     //out.print(a[i]);
     }
     
     
     
     conn.close();
     }
     catch(SQLException e){
     System.out.print(e);
     
     }
    
     %>
     
     
     <select>
     <%
     for(int i=0;i<a.length;i++){
     
    %>
     <option value="<%=a[i] %>"><%=a[i] %></option>
    <% 
      }
     
      %>
     
     </select>
  </body>
</html>

save.jsp:

<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
<%@ page import="java.sql.*" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'save.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <body>
   <%
   request.setCharacterEncoding("gbk");
   String id=request.getParameter("id");
    String name=new String(request.getParameter("name").getBytes("ISO-8859-1"));
     String yw=request.getParameter("yw");
      String sx=request.getParameter("sx");
       String yy=request.getParameter("yy");
   
   String sql="update grade set 姓名='"+name+"' ,语文="+yw+" ,数学="+sx+", 英语="+yy+" where 学号="+id; 
  // out.print(sql);
   Connection conn;
   Statement stmt;
   //Result
    try{
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    }
    catch(ClassNotFoundException e){
    System.out.print(e);
    }
    
    try{
    
    
    conn=DriverManager.getConnection("jdbc:odbc:1");
    stmt=conn.createStatement();
    int i=stmt.executeUpdate(sql);
    out.print("成功修改"+i+"条记录");
    conn.close();
    }
    catch(SQLException e){
     System.out.print(e);
    }
    %>
  </body>
</html>
search.jsp:

<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'search.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <body><form action="searchrs.jsp" action="post">
  请输入检索关键字<input type="text" name="name" size="20">
  <input type="submit" value="检索">
  
  </form> 
  </body>
</html>

searchrs.jsp:

<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
<%@ page import="java.sql.*" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'searchrs.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <body>
    <%
     Connection conn;
    Statement stmt;
    ResultSet rs;
    String name=new String(request.getParameter("name").getBytes("ISO-8859-1"));

    String sql="select * from grade where 姓名 like '%"+name+"%'";
        // out.print(sql);
         
       
    try{
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    }
    catch(ClassNotFoundException e){
    System.out.print(e);
    }    
     try{
    conn=DriverManager.getConnection("jdbc:odbc:1");
    stmt=conn.createStatement();
    rs=stmt.executeQuery(sql);
    while(rs.next()){
    out.print(rs.getString(2)+"<br>");
    
    }
    conn.close();
    }
    catch(SQLException e){System.out.print(e);}    
         
     %>
  </body>
</html>

view.jsp:

<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
<%@ page import="java.sql.*" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'view.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <body>
    <%
    Connection conn;
    Statement stmt;
    ResultSet rs;
    
    request.setCharacterEncoding("gbk");
    String id=request.getParameter("id");
    String sql="select * from grade where 学号="+id;
    System.out.print(sql);
    out.print(id);
     Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
     
     conn=DriverManager.getConnection("jdbc:odbc:1");
     stmt=conn.createStatement();
    rs=stmt.executeQuery(sql);
    rs.next();
    
    out.print(rs.getString(1)+"<br>");
      out.print(rs.getString(2)+"<br>");
        out.print(rs.getString(3)+"<br>");
          out.print(rs.getString(4)+"<br>");
            out.print(rs.getString(5)+"<br>");
        
     conn.close();
     
    
    
    
    
     %>
  </body>
</html>




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值