解决方案 »

  1.   


                      obj = Ext.util.JSON.decode(action.response.responseText);
    登录失败,这句报错
      

  2.   

    defaultType:'textfield',改为
    type:'text/json',看哈
      

  3.   

    lz,你用extjs做的登陆
    login.getForm().submit({
        waitTitle:"请稍后",
        waitMsg:'正在登录...',
        method:'POST', 
        url:'j_spring_security_check',
        ... 
    });
    这是异步的后台是不能控制页面跳转的,需要后台返回success标志通过js调整才行的。而根据你spring security的配置,登陆失败是返回一个jsp页面,导致Ext.util.JSON.decode(action.response.responseText)解析的不是json字符串报错!解决办法就是让spring security在验证登陆的时候返回json字符串给extjs,把配置改改:
    <!-- 自定义一个认证成功或失败时的Handler -->
    <beans:bean id="authenticationHandler" class="com.xxxx.AuthenticationHandler" />
    ...
    <!-- 告诉spring security认证后交给authenticationHandler去处理 -->
    <form-login login-page="/login.jsp" 
        authentication-success-handler-ref="authenticationHandler"
        authentication-failure-handler-ref="authenticationHandler" />
    ...
    AuthenticationHandler实现AuthenticationSuccessHandler和AuthenticationFailureHandler接口
    import java.io.IOException;import javax.servlet.ServletException;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import javax.servlet.http.HttpSession;import org.springframework.security.core.Authentication;
    import org.springframework.security.core.AuthenticationException;
    import org.springframework.security.web.WebAttributes;
    import org.springframework.security.web.authentication.AuthenticationFailureHandler;
    import org.springframework.security.web.authentication.AuthenticationSuccessHandler;public class AuthenticationHandler implements AuthenticationSuccessHandler, AuthenticationFailureHandler
    {    @Override
        public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication auth) throws IOException, ServletException
        {
            response.getWriter().println("{\"success\" : true}");
            clearAuthenticationAttributes(request);
        }    @Override
        public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException auth) throws IOException, ServletException
        {
            response.getWriter().println("{\"success\" : false, \"msg\" : \"权限认证失败!" + auth.getMessage() + "\"}");
            System.out.println(auth.getMessage());
        }
        
        /**
         * Removes temporary authentication-related data which may have been stored in the session
         * during the authentication process.
         */
        protected final void clearAuthenticationAttributes(HttpServletRequest request)
        {
            HttpSession session = request.getSession(false);        if(session == null)
            {
                return;
            }        session.removeAttribute(WebAttributes.AUTHENTICATION_EXCEPTION);
        }}在extjs登陆事件中:
    ...
    success : function() {
        window.location.href = 'index.html'; //跳转到登陆成功后的页面
    }
    ...
      

  4.   


    对,使用 
    ...
    success : function() {
        window.location.href = 'index.html'; //跳转到登陆成功后的页面
    }
    ...就可以实现在客户端的跳转到主页。