shIro跳转方法https服务变为http请求的问题解决办法
当https服务收到http请求时会有异常无法访问的错误。具体shiro的重定向方法如下:
Map<String,Object> queryParams = new HashMap<>();
queryParams.put("kickoutLoginMsg", "您的账号在别处地点登录,您已被迫踢出登录!");
queryParams.put("kickout", "1");
//request.setAttribute("kickoutlogin", "您的账号在别处地点登录,您已被迫踢出登录!");
//request.setAttribute("kickout", "1");
String ssoRelogin = UtilPropertiesFile.getInstance().get("sso_relogin");
WebUtils.issueRedirect(request, response, ssoRelogin, queryParams, true, false);
/* String contextPath = request.getContextPath();
String ssoRelogin = UtilPropertiesFile.getInstance().get("sso_relogin");
response.setStatus(302);//或者303,兼容http1.1
response.setHeader("location", contextPath + ssoRelogin+"?kickout=1");
WebUtils.toHttp(response).sendRedirect(contextPath + ssoRelogin+"?kickout=1");*/
网上流传的解决办法无非两种,一种是修改springmvc配置文件
<!-- Jsp视图 -->
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="order" value="1"/>
<property name="prefix" value="/WEB-INF/jsp"/>
<property name="suffix" value=""/>
<property name="contentType" value="text/html; charset=utf-8"/>
<!-- redirectHttp10Compatible:解决https环境下使用redirect重定向地址变为http的协议,无法访问服务的问题,设置为false,即关闭了对http1.0协议的兼容支持-->
<property name="redirectHttp10Compatible" value="false" />
</bean>
还有一种是设置response
两种办法都试过,但都无效,查看shiro源码才发现,shiro需要自己指定redirectHttp10Compatible设置方式。无论怎么设置当你用了shiro的重定向,最终都会默认redirectHttp10Compatible为true,所以需要自己指定为false