1.如果查看shiro源碼可以發現,這裏確實是一個坑
默認登陸成功後跳轉的是剛纔訪問的頁面(也就是登陸頁面),其次纔是/
你們可以實現一個類繼承至FormAuthenticationFilter,跟着這個類,一點一點去查即可
我先說一下網上的解決辦法
這是我按照網上的寫法實現的
package com.read.data.Config; import org.apache.shiro.authc.AuthenticationToken; import org.apache.shiro.subject.Subject; import org.apache.shiro.web.filter.authc.FormAuthenticationFilter; import org.apache.shiro.web.util.WebUtils; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; /** * @author: tianyong * @Time: 2018/8/15 11:36 * @description:shiro過濾器類 */ public class ShiroFilter extends FormAuthenticationFilter { /** * @author: tianyong * @time: 2018/8/15 11:42 * @description:重寫原認證成功後鏈接跳轉方法 */ @Override protected void issueSuccessRedirect(ServletRequest request, ServletResponse response) throws Exception { WebUtils.issueRedirect(request, response,getSuccessUrl(), null, true); } }
然後呢,方法的切入,現在網上的教程一般都是使用配置文件,我這裏是使用的spring4
//自定義過濾器注入 // Map<String, Filter> map = new HashMap<>(); // ShiroFilter shiroFilter = new ShiroFilter(); // map.put("authc",new ShiroFilter()); // shiroFilterFactoryBean.setFilters(map);
這個我是在shiroFilter,方法攔截器裏面添加的,主要的應該就是最後一句的注入
採用上面的這個方法,我只有在打斷點的情況下,纔好使。
後來呢,我是直接在登陸的controller層做重定向控制實現的避免了這個問題