网上找到了良格戈的关于acegi的学习教程,按照他的做法,基本可以运行了,但是关于他提的如果输入登录信息错误,可以进行提示并且给了事例代码
<%@ taglib prefix="c" uri="WEB-INF/c.tld"%><html>
<head>
</head>
<body>
<form action="j_acegi_security_check" method="POST">
<table>
<tr>
<td>
名稱:
</td>
<td>
<input type='text' name='j_username' value=''>
<c:if test="${not empty param.login_error}">
     <font color="red">使用者名稱或密碼錯誤,請重新登入!<BR>
     </font>
</c:if>

</td>
</tr>
我试了死活是不出"使用者名稱或密碼錯誤,請重新登入!"这句话,我已经加了jstl包,请高手指点

解决方案 »

  1.   

    <%@ page language="java" pageEncoding="GBK"%>
    <%@ page import="org.acegisecurity.ui.AbstractProcessingFilter"%>
    <%@ page import="org.acegisecurity.AuthenticationException"%>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
    <html>
    <head> <title>登录页面</title>
    <s:head />
    <script type="text/javascript">
    function checkLogin(){
    var name = document.getElementById("userName").value;
    var pwd = document.getElementById("userPwd").value;
    var rand = document.getElementById("rand").value;
    var error = document.getElementById("ErrorDIV");
    error.innerHTML = "";
    if(!name=="" && !pwd==""){
    if(!rand=="")
    return true;
    else{
    error.innerHTML = "<font color=red>验证码不能为空!</font>";
    return false;
    }
    }else{
    error.innerHTML = "<font color=red>用户名或者密码不能为空!</font>";
    return false;
    }
    }
    function doAlert() {
    //alert('请输入正确的密码和验证码!');
     var rdiv = "<input name='agent.rootid' type='text' value='${agent.rootid}' id='rootid'>";
    document.getElementById("rootdiv").innerHTML=rdiv;
    }
    </script>
    </head>
    <body style="padding-top: 120px;">
    <center>
    <p style="font-size: 14px; font-family: fantasy">
    登录
    </p>

    ------------------------------------------------------------------------------------------------------------------
    <div id="ErrorDIV"></div>
    <c:if test="${not empty param.login_error}">
    <%
    if (session != null
    && session
    .getAttribute(AbstractProcessingFilter.ACEGI_SECURITY_LAST_EXCEPTION_KEY) != null) {
    %>
    <%
    out.println("<font color='red'>验证码错误!</font> " + request.getParameter("login_error") );
    }
    %>

    </c:if>
    <form name="LoginForm"
    action="<c:url value='j_acegi_security_check'/>"  onsubmit="return  checkLogin(); "/>
    <table>
    <tr>
    <td width="100px" align="center">
    用户名:
    </td>
    <td width="200px">
    <input type="text" id="userName" name="j_username"
    value="${ACEGI_SECURITY_LAST_USERNAME}">
    </td>
    </tr>
    <tr>
    <td width="100px" align="center">
    密码:
    </td>
    <td>
    <input type="password" name="j_password" id="userPwd">
    </td>
    </tr>
    <tr>
    <td width="100px" align="center">
    验证码:
    </td>
    <td>
    <input type=text name="rand" id="rand">
    <img border="0" src="image.jsp" />
    </td>
    </tr>
    <tr>
    <td colspan="2" align="center">
    <input type="submit" value="确定" />
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <input type="reset" value="取消">
    </td>
    </tr>
    <tr>
    </tr>
    </table>
    </form>
    </center>
    </body>
    </html>
      

  2.   

    主要是配置文件,<!-- 该Filter负责处理登陆身份验证。
    当接受到与filterProcessesUrl所定义相同的请求时,
    它会首先通过 AuthenticationManager来验证用户身份。
    如果验证成功,则重定向到defaultTargetUrl所定义的成功登陆页面。
    如果验证失败,则再从rememberMeServices中获取用户身份,若再获取失败,
    则重定向到authenticationFailureUrl所定义登陆失败页面。-->
    <bean id="authenticationProcessingFilter"
    class="com.tg.role.security.validateCode.HomeAloneAuthenticationProcessingFilter">
    <property name="authenticationManager"
    ref="authenticationManager" />
    <property name="authenticationFailureUrl"
    value="/Login.jsp?login_error=1" />
    <property name="defaultTargetUrl" value="/MainFrame.jsp" />
    <property name="filterProcessesUrl"
    value="/j_acegi_security_check" />
    <property name="rememberMeServices" ref="rememberMeServices" />
    <property name="exceptionMappings">
    <props>
    <prop
    key="com.eshore.util.ValidaAuthenticationException">
    /Login.jsp?login_error=1&amp;aa=2
    </prop>
    </props>
    </property> </bean>