1. 【急,在线等】filter拦截器拦截后为什么页面的样式都没了
估计你把静态资源都给拦截了,你又没设置 静态资源的映射..就会出现这种情况
2. springMVC的拦截器不拦截直接访问jsp的请求
你好,分享一下我的拦截器,多多指教,代码如下:
在spring的配置文件里面进行配置拦截器
<!-- 拦截器 -->
<mvc:interceptors>
<mvc:interceptor>
<!-- 对所有的请求拦截使用/**-->
<mvc:mapping path="/**" />
<ref bean="userAccessInterceptor" />
</mvc:interceptor>
</mvc:interceptors>
<bean id="userAccessInterceptor"class="com.web.interceptor.UserAccessInterceptor"></bean>
拦截器如下设置,当用户未登录时,返回到登录页面
class UserAccessInterceptor extends HandlerInterceptorAdapter {
@Override
public boolean preHandle(HttpServletRequest request,HttpServletResponse response, Object handler) throws Exception {
//静态资源直接return true
if(handler instanceof ResourceHttpRequestHandler){
return true;
}
if(Utils.isNull(UserCookie.getApploginUserId())){
response.sendRedirect(request.getContextPath()+"/login.jsp");
return false;
}
return true;
}
3. spring boot整合security 4,怎么设置忽略的静态资源
Spring Security默认会对静态文件进行拦截,这个问题在Spring MVC中也出现过,Spring MVC的解决办法是在配置文件中加入静态资源的引用配置,但是Spring boot + Spring Security整合中采用全注解方式,没有配置文件,因此需要进行如下改动:
@Configuration@EnableWebSecurity@EnableGlobalMethodSecurity(prePostEnabled = true) //开启security注解public class WebSecurityConfig extends WebSecurityConfigurerAdapter{
@Bean
@Override
protected AuthenticationManager authenticationManager() throws Exception {
return super.authenticationManager();
} @Override
protected void configure(HttpSecurity http) throws Exception { //允许所有用户访问"/"和"/home"
http.authorizeRequests()
.antMatchers("/home").permitAll() //其他地址的访问均需验证权限
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login") //指定登录页是"/login"
.defaultSuccessUrl("/list") //登录成功后默认跳转到"list"
.permitAll()
.and()
.logout()
.logoutSuccessUrl("/home") //退出登录后的默认url是"/home"
.permitAll();
} @Override
public void configure(WebSecurity web) throws Exception { //解决静态资源被拦截的问题
web.ignoring().antMatchers("/global/**");
}
}
Spring boot的默认静态资源放置位置是在resource/static下,可以在static下新建一个文件夹,然后在上述方法中指定跳过拦截的文件路径即可。
4. 请问,java高手,spring mvc拦截器如何拦截所有的请求啊,包括html和jsp页面
如果拦截所有的话,你应该用filter。
5. spring boot 整合security 4 怎么设置忽略的静态资源
public void configure(WebSecurity web) throws Exception {;
web.ignoring().antMatchers("/assets/**","/images/**","/**/*.jsp");
protected void configure(HttpSecurity http) throws Exception {;
http.portMapper().http(80).mapsTo(443);
http.addFilterBefore(mySecurityInterceptor,FilterSecurityInterceptor.class);
authorizeRequests();
//.antMatchers("/webapp/**").permitAll();
//.antMatchers("/images/*.jpg").permitAll();
//.antMatchers("/images/*.png").permitAll();
//.antMatchers("/**/*.js").permitAll();
//.antMatchers("/**/*.css").permitAll();
//.antMatchers("/**/*.woff").permitAll();
//.antMatchers("/**/*.woff2").permitAll();
//.antMatchers("/**/*.jsp").permitAll();
//.antMatchers("/**/*.html").permitAll();
//.antMatchers("/favicon.ico").permitAll();
//.antMatchers("/admin/*").permitAll();
//.antMatchers("/sys/**").permitAll();
anyRequest().authenticated().and();
ormLogin();
loginPage("/admin/login").permitAll();
loginProcessingUrl("/sys/welcome");
permitAll();
passwordParameter("loginPwd");
usernameParameter("loginId");
failureUrl("/admin/sessiontimeout");
logoutUrl("/admin/logout");
permitAll();
invalidateHttpSession(true);
and().exceptionHandling();
accessDeniedHandler(myAccessDeniedHandler);
accessDeniedPage("/admin/accessDefine");
and()。
6. spring mvc 3.0 如何解决.css、.js等静态文件被拦截问题
每个静态资源都是一次请求不是吗, 那你应该在web.xml里配置拦截*.action呀. 这样的话spring就拦截不到以.action结尾的其他所有文件了
登录的话, 建议还是用Apache shiro 来控制权限, shiro也可以进行资源的放行
7. springMvc+shiro做权限管理,页面上的静态资源,样式图片等没有出现,用几种方式过滤试过,还是不行
正常情况是不会出现这样的,shiro对于静态资源的处理,不用特殊配置。
只需要在shiroFilter过滤器filterChainDefinitions项中增加一个静态资源处理规则就可以,例如允许/css/开头的资源匿名访问,只需要这样一句配置就足矣。
/css/** = anon
配置完成后,未登录就可以在浏览器中直接访问css下的资源,新项目用的shiro,简单而又实用的权限框架。
8. 不知道怎么回事fiddler和charles抓包都抓不到Js,其他的接口请求啊html啊都能抓到
你好,抄
你这个问题如果是正常情袭况(没有Filter或其他过滤设置)下发生的,多半是由于浏览器缓存导致。
静态资源缓存后,浏览器不会向服务端发起请求,请求到不了fiddler等抓包软件,所以抓不到。
解决方法:
手动清除浏览器缓存后,强制刷新页面再抓试试;
打开“开发者工具-Network”,勾选“Disable cache”,保持开发者工具打开状态下,强制刷新页面;
开发调试阶段,为静态资源添加时间戳参数,防止缓存(xxxx.js?_t=时间戳)
希望能解决你的问题,如按以上方式都无法解决可以在追问中详细描述下你的操作流程。
9. shiro的filterchaindefinitions路径中可以带参数吗
正常情况是不会出现这样的,shiro对于静态资源的处理,不用特殊配置,只需要在shiroFilter过滤器filterChainDefinitions项中增加一个静态资源处理规则就可以,例如允许/css/开头的资源匿名访问,只需要这样一句配置就足矣, /css/** = anon 配置.