📄 show_s_info2.jsp
字号:
<%-----filename:show_show_s_info2.jsp------教师使用多条件组合,查询学生信息时,处理查询和显示结果的页面-------%>
<%/*
--------本网页需要接收两个输入参数:request.getPrameter("text0"),session.getAttribute("zhanghao")--------------
*/%>
<!-------------zhg工作室------2007.6------------->
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<%
String zhanghao = (String)session.getAttribute("zhanghao");
if(zhanghao==null)
{
response.sendRedirect("login.html");//避免未经登录直接进入本页面
}
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>欢迎使用----成绩查询系统</title>
</head>
<body bgColor="#9999cc">
<%/*
<script language="javascript">
<!--
document.bgColor="#9999cc";
//-->
</script>
*/%>
<%@ include file="jdbc.jsp" %>
<%--
//这一部分通过包含公共文件jdbc.jsp 来实现
String driver = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
String Host = "localhost";
String Port = "1433";
String DBName = "marks_query"; //要操作的数据库
String MssqlURL = "jdbc:microsoft:sqlserver://" + Host + ":" + Port +
";DatabaseName=" + DBName + ";SelectMethod=cursor";
String UserName = "sa"; //数据库服务器登录账号
String PassWord = ""; //登录密码
--%>
<%
//String zhanghao=null,mima=null;//记录客户端输入的账号和密码
String sql=null;
ResultSet rs = null;
%>
<%
try {
Class.forName(driver);
Connection conn = DriverManager.getConnection(MssqlURL, UserName,PassWord); Statement stmt= conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
String property1 = new String(request.getParameter("select1").getBytes("ISO8859_1"));//获取要查询的学生的第1个属性
String property2 = new String(request.getParameter("select2").getBytes("ISO8859_1"));//获取要查询的学生的第2个属性
String property3 = new String(request.getParameter("select3").getBytes("ISO8859_1"));//获取要查询的学生的第3个属性
String value1 = new String(request.getParameter("text1").getBytes("ISO8859_1"));//获取要查询的学生的第1个属性的值
String value2 = new String(request.getParameter("text2").getBytes("ISO8859_1"));//获取要查询的学生的第2个属性的值
String value3 = new String(request.getParameter("text3").getBytes("ISO8859_1"));//获取要查询的学生的第3个属性的值
//如果不输入则不将其作为查询条件,否则其他值都必须显式输入,即使要查询数据库中值为null的信息也应当输入字符串null
//但是如果所有条件都不输入则变为查询全体学生
//如果输入框为空,则将属性作为要查询的表中的属性名,故采用恒等,否则将输入值作为查询值并且以字符串的形式使用。
String operator1="=";//默认使用‘等号’
if(value1.equals(""))
{
operator1="=";
value1=property1;
}
else if(value1.equals("null"))
{
operator1=" is ";
value1=value1;
}
else
{
operator1="=";
value1="'"+value1+"'";
}
String operator2="=";//默认使用‘等号’
if(value2.equals(""))
{
operator2="=";
value2=property2;
}
else if(value2.equals("null"))
{
operator2=" is ";
value2=value2;
}
else
{
operator2="=";
value2="'"+value2+"'";
}
String operator3="=";//默认使用‘等号’
if(value3.equals(""))
{
operator3="=";
value3=property3;
}
else if(value3.equals("null"))
{
operator3=" is ";
value3=value3;
}
else
{
operator3="=";
value3="'"+value3+"'";
}
// if(value2.equals("")) value2=property2; else value2="'"+value2+"'";
// if(value3.equals("")) value3=property3; else value3="'"+value3+"'";
//out.println(property1+"="+value1+", ");
sql = "select * from student,course,marks where student.学号=marks.学号 and course.课程号=marks.课程号 and student."+property1+operator1+value1+" and student."+property2+operator2+value2+" and course."+property3+operator3+value3;
//out.println("sql="+sql+",<br>");
rs = stmt.executeQuery(sql);
if(rs.next())//因为数据库login表中账号为主键,所以无需使用while遍历结果集
{
out.println(zhanghao+" 老师, 你所查询的学生的信息如下:");
%>
<br><hr>
<table border="1">
<tr>
<th>学号</th><th>姓名</th><th>性别</th><th>出生年月</th><th>专业</th><th>课程号</th><th>课程名</th><th>学分</th><th>性质</th><th>课时</th><th>成绩</th>
</tr>
<%
rs.previous();
while(rs.next())
{
%>
<tr>
<td><%=rs.getString("学号")%><td><%=rs.getString("姓名")%></td><td><%=rs.getString("性别")%></td><td><%=rs.getString("出生年月")%></td><td><%=rs.getString("专业")%></td><td><%=rs.getString("课程号")%><td><%=rs.getString("课程名")%></td><td><%=rs.getString("学分")%></td><td><%=rs.getString("性质")%></td><td><%=rs.getString("课时")%></td><td><%=rs.getString("成绩")%></td>
</tr>
<%
}
%>
</table>
<%
}
else out.println(zhanghao+" 老师,没有符合您所要查的学生的信息!请确认您输入的查询条件正确!<hr>");
%>
<%
rs.close();
stmt.close();
conn.close();
}
catch(Exception e) {
out.println("出现错误!!!请检查各相关软件的设置!!!<p>下面的出错提示可供参考:<br><font color='red'>" + e+"</font></p><br><br>----ZHG工作室------2007.6 ");
}
%>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -