```html
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%
' *** Validate request to log in to this site.
MM_LoginAction = Request.ServerVariables("URL")
If Request.QueryString <> "" Then MM_LoginAction = MM_LoginAction + "?" + Server.HTMLEncode(Request.QueryString)
MM_valUsername = CStr(Request.Form("name"))
If MM_valUsername <> "" Then
Dim MM_loginSQL, MM_fldUserAuthorization
MM_loginSQL = "SELECT username, psw FROM login_user WHERE username = ? AND psw = ?"
MM_fldUserAuthorization = "" ' 如果需要获取用户权限字段,请设置为对应的字段名
Dim conn, MM_rsUser_cmd, MM_rsUser,MM_conn2_STRING
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open MM_conn2_STRING ' 打开数据库连接字符串
Set MM_rsUser_cmd = Server.CreateObject("ADODB.Command")
MM_rsUser_cmd.ActiveConnection = conn
With MM_rsUser_cmd
.CommandType = 1 ' adCmdText,命令类型为文本
.CommandText = MM_loginSQL ' 设置SQL语句
.Prepared = true ' 预编译SQL语句
.Parameters.Append .CreateParameter("username", 200, 1, 50, MM_valUsername) ' 添加参数
.Parameters.Append .CreateParameter("password", 200, 1, 50, Request.Form("psw")) ' 添加参数
End With
Set MM_rsUser = MM_rsUser_cmd.Execute
If Not MM_rsUser.EOF Or Not MM_rsUser.BOF Then
' 进行验证码验证
Dim input_code
input_code = Request.Form("input_code")
If LCase(input_code) <> LCase(Session("CheckCode")) Then
Response.Write("<script>alert('验证码输入错误,请重新输入。')</script>")
Else
Session("MM_Username") = MM_valUsername
If (MM_fldUserAuthorization <> "") Then
Session("MM_UserAuthorization") = CStr(MM_rsUser.Fields.Item(MM_fldUserAuthorization).Value)
Else
Session("MM_UserAuthorization") = ""
End If
if CStr(Request.QueryString("accessdenied")) <> "" And True Then
MM_redirectLoginSuccess = Request.QueryString("accessdenied")
End If
MM_rsUser.Close
Response.Redirect(MM_redirectLoginSuccess)
End If
' 否则跳转到登录失败页面
Else
MM_rsUser.Close
Response.Redirect(MM_redirectLoginFailed)
end if
end if
%>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
body {
background-image: url(%E5%9B%BE%E7%89%87/amelia-barklid-CUmCByAhXyQ-unsplash.jpg);
background-size: cover;
background-position: center;
}
.indexfont {
color: #FFF;
font-size: 24px;
text-align: center;
font-weight: bold;
}
.indextablefont {
color: #000;
font-weight: bold;
}
</style>
<script type="text/javascript">
function MM_openBrWindow(theURL,winName,features) { //v2.0
window.open(theURL,winName,features);
}
window.onload = function() {
draw();
}
// 绘制验证码
function draw() {
var canvas = document.getElementById("canvas");
var context = canvas.getContext("2d");
context.fillStyle = "#fff";
context.fillRect(0, 0, 120, 40);
context.font = "bold 30px Arial";
var aCode = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"];
var len = aCode.length - 1;
var code = "";
for (var i = 0; i < 4; i++) {
var index = Math.round(Math.random() * len);
var c = aCode[index];
code += c;
context.fillStyle = "#" + (Math.random() * 0xffffff << 0).toString(16);
context.fillText(c, i * 25 + 20, 30);
}
//将验证码保存到隐藏的input标签和Session中
document.getElementById("code").value = code;
<% Session("CheckCode") = "'" & code & "'" %>
}
// 提交表单并验证验证码
function submitForm() {
var form = document.getElementById("user_login");
var code = document.getElementById("code").value;
var input_code= document.getElementById("input_code").value;
if (input_code.toLowerCase() === code.toLowerCase()) { // 判断用户输入的验证码是否正确
form.submit(); // 如果验证码正确,则提交表单
} else {
alert('验证码输入错误,请重新输入');
draw(); // 重新绘制验证码
document.getElementById("input_code").value = ""; // 清空用户输入的验证码
}
}
</script>
</head>
<body>
<table width="60%" border="1" align="center" cellpadding="0" cellspacing="0">
<tr>
<td bgcolor="#0099FF" class="indexfont">::理工教学管理系统学生端登录::</td>
</tr>
<tr>
<td height="160" align="center">
<form ACTION="<%=MM_LoginAction%>" METHOD="POST" id="user_login" name="user_login">
<table width="60%" border="0" align="center">
<tr>
<td width="36%" class="indextablefont">Username:</td>
<td width="64%"><input type="text" name="name" id="name" /></td>
</tr>
<tr>
<td class="indextablefont">Password:</td>
<td><input type="password" name="psw" id="psw" /></td>
</tr>
<tr>
<td class="indextablefont">验证码:</td>
<td>
<canvas id="canvas" width="120" height="40"></canvas>
<input type="hidden" name="code" id="code">
<input type="text" name="input_code" id="input_code">
<input type="button" value="看不清,换一张" onclick="draw()">
</td>
</tr>
<tr>
<tr>
<td> </td>
<td><input type="button" value="登录" onclick="submitForm()" />
<input name="button2" type="button" id="button2" onClick="MM_openBrWindow('index_student_zhuce.asp','','')" value="注册" /></td>
</tr>
</table>
<input type="checkbox" name="checkbox" id="checkbox" />
已阅读接受
</form>
</td>
</tr>
<tr>
<td bgcolor="#00CCFF" class="indexfont">::48号版权所有::</td>
</tr>
<tr>
<td bgcolor="#0099FF" class="indexfont"><%= Request.QueryString("err") %></td>
</tr>
</table>
</body>
</html>
JSP啊,,,算了,
用PreparedStatement 一般来说比Statement性能高。
有外键约束会影响插入和删除性能,如果程序能够保证数据的完整性,那在设计数据库时就去掉外键。
根据扫描的原理,第一条子查询语句要比第二条关联查询的效率高:
1)select e.name,e.salary where e.managerid=(select id from employee where name=‘zxx’);
2)select e.name,e.salary,m.name,m.salary from employees e,employees m where e.managerid = m.id and m.name=‘zxx’;
表中允许适当冗余。如,主题帖的回复数量和最后回复时间等
将姓名和密码单独从用户表中独立出来。这可以是非常好的一对一的案例。
sql语句全部大写,特别是列名和表名都大写。特别是sql命令的缓存功能,更加需要统一大小写,sql语句?发给oracle服务器?语法检查和编译成为内部指令?缓存和执行指令。根据缓存的特点,不要拼凑条件,而是用?和PreparedStatment
还有索引对查询性能的改进也是值得关注的。