• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: 小 中 大 | 推荐给好友 上一篇 | 下一篇

简易成绩查询系统

发布: 2007-7-01 18:47 | 作者: admin | 来源: | 查看: 39次 | 进入软件测试论坛讨论

领测软件测试网 先建一个数据库(std.mdb):其中有两个表 1.pw(密码表) 2.score成绩表
然后建两个Jsp文件

enter.jsp(登录页面,用来验正身份的)
-----------------------------------------------
<%@ page contentType="text/html;charset=gb2312"%>
<html>
<title>个人成绩查询登录</title>
<body>
<center>
<font color=blue size=4><b><i>
请输入你的学号和密码</b></i>
</font>
<hr>
<form action="result.jsp" method="post">
<table border="1">
<tr><th bgcolor="yellow">学号</th><td>
<input type="text" size=10 name="number"></td></tr>
<tr><th bgcolor="yellow">密码</th><td>
<input type="password" size=10 name="password"></td></tr>
<tr><td colspan="2" align="center">
<input type="submit" vaule="查询"></td></tr>
</table>
</form>
<font color="red">
<%
String error=request.getParameter("errortype");
if(error!=null)
{
int errortype;
errortype=Integer.parseInt(error);
switch(errortype)
{
case 1:out.println("请输入学号!");break;
case 2:out.println("请输入密码!");break;
case 3:out.println("搞错,没有此人!");break;
case 4:out.println("密码错误!");break;
default:
}
}
%>
</font>
</body>
</html>



result.jsp(执行查询结果)
--------------------------------------------
<html>
<title>查询结果</title>
<body>
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*" %>
<%
String num=request.getParameter("number");
String password=request.getParameter("password");
int errortype=0;
if(num.equals(""))
{
errortype=1;
response.sendRedirect("enter.jsp?errortype="+errortype);
}
else if(password.equals(""))
{
errortype=2;
response.sendRedirect("enter.jsp?errortype="+errortype);
}
else
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("Jdbc:odbc:std");
Statement smt=con.createStatement();
String sql="select * from pw where 学号=@#"+num+"@#";
ResultSet rs=smt.executeQuery(sql);
if(!rs.next())
{
errortype=3;
response.sendRedirect("enter.jsp?errortype="+errortype);
}
else if(!rs.getString(2).equals(password))
{
errortype=4;
response.sendRedirect("enter.jsp?errortype="+errortype);
}
else
{

sql="select * from score where 学号=@#"+num+"@#";
rs=smt.executeQuery(sql);
rs.next();
out.println(rs.getString(1)+",你好,你的成绩如下:"+"<hr>");
out.println("<table border=@#1@#>");
out.println("<tr bgcolor=@#gray@#><th>姓名</th><th>计算机英语</th><th>软件工程</th><th>C程序设计</th><th>Java程序设计</th><th>数据库原理</th><th>计算机网络</th></tr>");
out.println("<tr><td>"+rs.getString(2)+"</td><td>"+rs.getString(3)+"</td></td>"+"</td><td>"+rs.getString(4)+"</td><td>"+rs.getString(5)+"</td><td>"+rs.getString(6)+"</td><td>"+rs.getString(7)+"</td><td>"+rs.getString(8)+"</td></tr>");
con.close();
}
con.close();
}
%>
</table>
</body>
</html>

文章来源于领测软件测试网 https://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备10010545号-5
技术支持和业务联系:[email protected] 电话:010-51297073

软件测试 | 领测国际 | ISTQB | ISTQB官网 | TMMi | TMMi认证 | 国际软件测试工程师认证 | 领测软件测试网