我做了一个简单的登陆页面,在adlogin.jsp中接收输入的用户名和密码,存到Administer的javabean中,然后在switch.jsp 中验证,奇怪的是无论输入的密码是否正确,都跳转到/login/fail.jsp这个页面。
代码如下:
adlogin.jsp的代码:
<%@page contentType="text/html; charset=GBK" import="common.AdministerList" errorPage="error.jsp"%>
<html>
<head>
<title>adlogin</title>
</head>
<body bgcolor="#ffffff">
<form name="form1" method="post" action="/ECWeb/login/switch.jsp">
<!-- <form name="form1" method="post" action="/ECWeb/admiLoginAction.do">-->
<table align="center" bgcolor="ccffcc" border="0" cellspacing="20">
<tr>
<td>用户名:</td>
<td align="left">
<select name="admiName">
<option value="" selected>--选择管理员登陆名称--</option>
<%=AdministerList.getAdmiListHTML()%> </select>
</td>
</tr>
<tr>
<td width="100"> 密
 
码:
</td>
<td align="center" width="30">
<input name="admiPassword" type="password">
</td>
</tr>
<tr>
<td height="30" align="right">
<input type="submit" name="submit" value="确认" align="middle"/>
</td>
<td height="30" align="center">
<input type="reset" name="reset" value="清空" align="middle"/>
</td>
</tr>
</table>
</form>
</body>
</html>
switch.jsp 的代码:
<%@ page contentType="text/html; charset=GBK" errorPage="error.jsp" %>
<%@ page import="common.*"%>
<%@page import="java.sql.*"%>
<jsp:useBean id="administerBean" scope="page" class="common.Administer" />
<jsp:setProperty name="administerBean" property="*" />
<%
Connection conn = null;
try {
conn = DBConnection.getConnection();
String newName=administerBean.getAdmiName();
String newPassword=administerBean.getAdmiPassword();
String sql="select admiId from AdmiInfo where admiName=newName and admiPassword=newPassword";
Statement Stmt=conn.createStatement();
ResultSet rs = Stmt.executeQuery(sql);
if (rs.next()) { //密码正确
administerBean.setAdmiId(Long.parseLong(rs.getString("admiId")));
session.setAttribute("ses_administerBean", administerBean);
%>
<jsp:forward page="/login/adindex.jsp"></jsp:forward>
<%} else { //密码错误%>
<jsp:forward page="/login/fail.jsp"></jsp:forward>
<%
}} finally {
if (conn != null) conn.close();
}
%>
Administer的代码:
package common;
import javax.servlet.http.HttpSessionBindingListener;
import javax.servlet.http.HttpSessionBindingEvent;
import java.sql.*;
import java.text.SimpleDateFormat;
import java.util.Date;
public class Administer
{
private long admiId;
private String admiPassword;
private String admiName;
public String getAdmiPassword()
{
return admiPassword;
}
public long getAdmiId()
{
return admiId;
}
public String getAdmiName()
{
return admiName;
}
public void setPassword(String admiPassword)
{
this.admiPassword = admiPassword;
}
public void setAdmiId(long admiId)
{
this.admiId = admiId;
}
public void setAdmiName(String admiName)
{
this.admiName = admiName;
}
}
请各位帮忙看看,谢谢了~~~