一、問題web
使用shiro重定向方法,apache
redirectToSavedRequest(ServletRequest request, ServletResponse response, String fallbackUrl)
出現重定向的url爲:baidu.com/;JSSESSIONID=33323KLJ3LK4?a=1&b=3。致使瀏覽器識別不了瀏覽器
二、出現緣由session
a.查看源碼可知,是因爲app
ShiroHttpServletResponse
protected String toEncoded(String url, String sessionId) { if (url != null && sessionId != null) { String path = url; String query = ""; String anchor = ""; int question = url.indexOf(63); if (question >= 0) { path = url.substring(0, question); query = url.substring(question); } int pound = path.indexOf(35); if (pound >= 0) { anchor = path.substring(pound); path = path.substring(0, pound); } StringBuilder sb = new StringBuilder(path); if (sb.length() > 0) { sb.append(";"); sb.append("JSESSIONID"); sb.append("="); sb.append(sessionId); } sb.append(anchor); sb.append(query); return sb.toString(); } else { return url; } }
拼接上的JSESSIONID。ui
3.解決方法url
a.重寫ShiroHttpServletResponse,參考文章:https://blog.csdn.net/aofavx/article/details/51701012.net
b.在shiro1.3.2版本中,官方提供了配置屬性。sessionIdUrlRewritingEnabled默認爲true。參考文章:https://blog.csdn.net/yyf314922957/article/details/51038322code
<!-- 會話管理器 -->blog
<bean id="sessionManager" class="org.apache.shiro.web.session.mgt.DefaultWebSessionManager">
<property name="sessionIdUrlRewritingEnabled" value="false" />
</bean>
使用方法在