日期:2014-05-18  浏览次数:20710 次

各位兄弟,我想问一个有关登陆验证的问题.....小弟急啊!
我的一个后台登陆页面中调用了登陆验证(login.java)类中的一个方法,这个方法返回一个boolean类型,如果返回false,刚登陆失败,但怎么样都只返回false,可是单独进行测试的时候却是正确的,各位帮我看看,谢谢:

index.jsp:部分代码:
<%
response.setHeader( "Pragma ", "No-cache ");
response.setHeader( "Cache-Control ", "no-cache ");
response.setDateHeader( "Expires ",   0);
request.setCharacterEncoding( "GBK ");           //设置编码方式为gb2312
//处理表单,并进行异常处理
String   Action   =   request.getParameter( "Action ");
if(Action!=null   &&   Action.equals( "Login "))
{
String   Page1     =   (String)request.getHeader( "Referer ");//得到页面地址来源
String   Page2     =   request.getRequestURL().toString();//得到当前页面地址
String   methon   =   request.getMethod();
if   (methon.equals( "POST ")   &&   Page2.equals(Page1))
{
try{
Function   Fun   =   new   Function();
//System.out.println( "成功! ");
dreamtime.dreamnews.Login   login   =   new   dreamtime.dreamnews.Login();
String   IP   =   request.getRemoteAddr();//得到客户端Ip地址
//System.out.println(IP);
String   User   =   request.getParameter( "User ");           //得到登录用户名
//System.out.println( "用户名: "   +   User);
String   Pwd   =   request.getParameter( "Pwd ");               //得到登录密码
//System.out.println( "登陆密码: "   +   Pwd);
String   sCode   =   Fun.CheckReplace(request.getParameter( "VerifyCode "));
if(!sCode.equals(session.getAttribute( "VerifyCode ")))
{
session.setAttribute( "error ", " <li> 验证码错误 ");
response.sendRedirect( "index.jsp ");
return;
}
if   (login.LoginCheck(User,Pwd,IP))
{
//System.out.println(login.LoginCheck(User,Pwd,IP));
session.setAttribute( "Login ", "Yes ");
session.setAttribute( "AdminID ",Integer.toString(login.AdminID));
session.setAttribute( "AdminType ",Integer.toString(login.AdminType));
session.setAttribute( "AdminName ",User);
session.setAttribute( "error ", " ");
out.println( " <SCRIPT   LANGUAGE= 'JavaScript '> alert( '登录成功! ');location.href= 'Admin_Main.jsp '; </SCRIPT> ");
return;
}
else  
{
session.setAttribute( "error ", " <li> 用户名或密码错误 ");
out.println( " <SCRIPT   LANGUAGE   =   'JavaScript '> alert( '用户名或密码错误 '); </SCRIPT> ");
response.sendRedirect( "index.jsp ");
return;
}
}catch(Exception   e){
response.sendRedirect( "index.jsp ");
session.setAttribute( "error ", " ");
return;
}
}
else
{
response.sendError(403, "禁止访问 ");
//out.print( "出错 "   +   Page1   +   "; "   +   Page2);
return;
}
}
%>
Login.java:
package   dreamtime.dreamnews;

import   java.sql.*;

import   dreamtime.dreamnews.DBConnection;
import   dreamtime.dreamnews.Function;
import   dreamtime.dreamnews.MD5;

public   class   Login   {
DBConnection &nbs