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 配置.