解决方案 »
- $("#fielditems")为什么要加个#符号》?不加不是也可以吗
- 弱弱问个问题关于ssh各种包的问题
- 如何用pentaho report designer 事先动态列报表
- 求救:socket服务程序僵死,急
- spring 的jdbctemplate不支持getMoreResult吗?
- 关于Spring与其他框架集成的问题?
- 初学struts,想向大虾要个类似论坛的实例来学习
- 问一下jsp的经典书籍?
- java 如何将数据转化为图形数据报表?
- webService基本原理
- 当java程序突发性的出现错误你该怎样解决
- myeclipse9中的MyEclipse Configuration Center菜单突然找不到了
obj = Ext.util.JSON.decode(action.response.responseText);
登录失败,这句报错
type:'text/json',看哈
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'; //跳转到登陆成功后的页面
}
...
对,使用
...
success : function() {
window.location.href = 'index.html'; //跳转到登陆成功后的页面
}
...就可以实现在客户端的跳转到主页。