In the video tutorial, the problem of jumping to the page after the request for authentication is successful is a one-off, but I think it is necessary to write a separate article to describe it.
I used SSH to integrate Shiro. During the post-development verification process, Shiro will jump to an unknown js after every login. But the point is that the address I visited last time was:
http://localhost:8080/shiro_05/user/login.action
After authentication, it should jump to the address of the previous request, but Shiro jumped to:
http://localhost:8080/shiro_05/user/js/eqmt.js
Should have jumped to the last page visited. However, it jumps to the request path of this js file, and this path is still strange.
I guess this question should be bothering a lot of people. Even if js, css and other directories are configured with anonymous access, etc., this problem still occurs: [The address jumps randomly after authentication, not the address where the last one you requested came in]. Some people even abandoned Shiro's own "jump to the previous request path" function. There should be a lot of people who have overcome this problem. Here, I will briefly talk about it.
After inspection, I finally found the problem: there is also a request address with a non-absolute path in the page!
This article is the original cat. Please add this link to reprint: http://blog.csdn.net/nthack5730/article/details/51132560
Lots of other articles about old cats: http://blog.csdn.net/nthack5730
First of all, let's talk about the address or request to be redirected after the default authentication is configured in Shiro:
In the bean configuration of shiroFilter
<bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
....
</bean>
Add the address parameters after successful verification:
<property name="successUrl" value="/user/list.action" />
It will be able to automatically forward to the address in the value every time after the authentication is successful (I use /user/list.action here. That is, to request this address)
When this parameter is not configured, Shiro will actively request the address you visited last time. if. Your visit address:
http://localhost:8080/shiro_01/user/
Now if this address needs to be authenticated to be accessed, that is, it is configured in the filter chain as
/user/** = authc
那么就会进入认证页面。而上面的地址就会被保存至Shiro中,当认证通过后,会自己主动请求浏览器訪问刚刚保存的地址。
http://localhost:8080/shiro_01/user/
可是当页面文件载入不对,在认证完毕后就会訪问地址:
http://localhost:8080/shiro_01/user/***.***
我的改动前的页面在认证后浏览器会去訪问以下这个地址:
http://localhost:8080/shiro_01/user/js/eqmt.js
此文老猫原创。转载请加本文连接:http://blog.csdn.net/nthack5730/article/details/51132560
很多其它有关老猫的文章:http://blog.csdn.net/nthack5730
为什么会出现这个问题呢,原因就在于登陆页面中也许有部分的第三方载入的样式、js等文件没有被正确录入。什么是不对录入。仅仅要是请求本地server,或者请求为:
http://localhost:8080/shiro_01/*******.***
这样的形式的,也就是在认证前和你上一个訪问的页面之间再訪问本server被shiro拦截的随意地址。就会被Shiro自己主动保存至上一个请求地址的这个变量中。当你认证完毕后会Shiro就会要求你的浏览器自己主动跳转到这个地址。
【注:CDN挂载载入的不算。由于不是请求本server。】
以下给出我的页面代码。里面的请求【自带js】这部分就是为http请求的而不是绝对路径载入进来的:
<!-- 公共样式文件引入 -->
<jsp:include page="Template/css.jsp"></jsp:include>
<!-- 自带js -->
<script src="js/eqmt.js"></script>
<!-- 自建样式表 -->
<link href="${pageContext.request.contextPath}/css/eqmt.css" rel="stylesheet" type="text/css">
<link href="${pageContext.request.contextPath}/css/login.css" rel="stylesheet" type="text/css">
除了:
<script src="js/eqmt.js"></script>
这个载入通过绝对路径载入不成功。然后浏览器自己主动訪问了相对地址,即浏览器用http的形式訪问,Shiro记录这个eqmt.js文件的訪问地址(还是错误的地址)其它的都是内部绝对路径訪问的。
【我在过滤链里面配置了相应绝对路径的文件的匿名訪问】
仅仅要将错误载入的代码改正或删除或者将文件挂载到cdn訪问,问题就能够攻克了:
<script src="${pageContext.request.contextPath}/js/eqmt.js"></script>
PS:里面的:${pageContext.request.contextPath}是我的项目地址。
JSP有这个蛋疼的问题,相信非常多人都知道。
【上面的总结是我个人感受写的,可能详细的学名和形容词在形容的过程中用得不恰当。望大家发现后指出并帮忙纠正。感激不尽!
】
此文老猫原创。转载请加本文连接:http://blog.csdn.net/nthack5730/article/details/51132560
很多其它有关老猫的文章:http://blog.csdn.net/nthack5730