本人是一个新手,刚开始学jsp,用的jsp平台是tomcat5.0,数据库是SQL Server 2000。现在要实现一个登陆,代码如下:
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
<style type="text/css">
<!--
.style1 { font-size: 14px;
color: #0000FF;
}
-->
</style>
<link href="../css/style.css" rel="stylesheet">
<script language="javascript">
<!--
function check(){
if(form1.users.value==""){
alert("请输入申报员登录名称");
form1.users.focus();
return false;
}
if(form1.passwords.value==""){
alert("请输入申报员密码");
form1.passwords.focus();
return false;
}
}
-->
</script>
</head>
<body>
<p> </p>
<p> </p>
<%
if request.getParameter("substr").equals("") {
%>
<table width="300" height="121" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#ffffff" bordercolordark="#D6E3D6" bordercolorlight="#FFFFFF">
<form action="login.jsp" method="post" name="form1">
<tr align="center" valign="middle" bgcolor="#F7F3EF">
<td height="30" colspan="2"><span class="style1">申报员登录</span></td>
</tr>
<tr>
<td height="30" align="center" valign="middle">用户名:</td>
<td width="172" align="left" valign="middle"><input name="users" type="text" class="txt_grey" id="users" style="width:120pt;">
</td>
</tr>
<tr>
<td height="30" align="center" valign="middle">密 码:</td>
<td height="30" align="left" valign="middle"><input name="passwords" type="password" class="txt_grey" id="passwords" style="width:120pt;">
</td>
</tr>
<tr align="center" bgcolor="#F7F3EF">
<td height="30" colspan="2" valign="middle"><input name=substr type="submit" class="btn_grey" onClick="return check()" value="提交">
<input name="Submit2" type="reset" class="btn_grey" value="重置"></td>
</tr>
</form>
</table>
<%} else {%>
<%@ include file="conn.jsp" %>
<%
String name=new String(request.getParameter("users").getBytes("8859_1"));
String pwd=new Sting(request.getParameter("passwords").getBytes("8859_1"));
String sql="select * from tb_user where users='"+name+"' and passwords='"+pwd+"'+ and levels='申报员'";
rs=stmt.executeQuery(sql);
if(rs.next()){
session.putValue("users",name);
session.putValue("passwords",pwd);
%>
<script language=javascript>
alert('登录成功 进入申报首页');
window.location="../declare.htm";
</script>
<% }
else{
%>
<script language=javascript>
alert('输入申报员名或密码有误');
window.location="login.jsp"</script>
<%
}
}
%>
</body>
</html>
但不知错误在那里,希望各位高手指点一下
谢谢