導航:首頁 > 凈水問答 > filter不過濾靜態資源

filter不過濾靜態資源

發布時間:2022-02-12 12:30:44

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 怎麼設置忽略的靜態資源

  1. public void configure(WebSecurity web) throws Exception {;

  2. web.ignoring().antMatchers("/assets/**","/images/**","/**/*.jsp");

  3. protected void configure(HttpSecurity http) throws Exception {;

  4. http.portMapper().http(80).mapsTo(443);

  5. http.addFilterBefore(mySecurityInterceptor,FilterSecurityInterceptor.class);

  6. authorizeRequests();

  7. //.antMatchers("/webapp/**").permitAll();

  8. //.antMatchers("/images/*.jpg").permitAll();

  9. //.antMatchers("/images/*.png").permitAll();

  10. //.antMatchers("/**/*.js").permitAll();

  11. //.antMatchers("/**/*.css").permitAll();

  12. //.antMatchers("/**/*.woff").permitAll();

  13. //.antMatchers("/**/*.woff2").permitAll();

  14. //.antMatchers("/**/*.jsp").permitAll();

  15. //.antMatchers("/**/*.html").permitAll();

  16. //.antMatchers("/favicon.ico").permitAll();

  17. //.antMatchers("/admin/*").permitAll();

  18. //.antMatchers("/sys/**").permitAll();

  19. anyRequest().authenticated().and();

  20. ormLogin();

  21. loginPage("/admin/login").permitAll();

  22. loginProcessingUrl("/sys/welcome");

  23. permitAll();

  24. passwordParameter("loginPwd");

  25. usernameParameter("loginId");

  26. failureUrl("/admin/sessiontimeout");

  27. logoutUrl("/admin/logout");

  28. permitAll();

  29. invalidateHttpSession(true);

  30. and().exceptionHandling();

  31. accessDeniedHandler(myAccessDeniedHandler);

  32. accessDeniedPage("/admin/accessDefine");

  33. 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等抓包軟體,所以抓不到。

解決方法:

  1. 手動清除瀏覽器緩存後,強制刷新頁面再抓試試;

  2. 打開「開發者工具-Network」,勾選「Disable cache」,保持開發者工具打開狀態下,強制刷新頁面;

  3. 開發調試階段,為靜態資源添加時間戳參數,防止緩存(xxxx.js?_t=時間戳)

希望能解決你的問題,如按以上方式都無法解決可以在追問中詳細描述下你的操作流程。

9. shiro的filterchaindefinitions路徑中可以帶參數嗎

正常情況是不會出現這樣的,shiro對於靜態資源的處理,不用特殊配置,只需要在shiroFilter過濾器filterChainDefinitions項中增加一個靜態資源處理規則就可以,例如允許/css/開頭的資源匿名訪問,只需要這樣一句配置就足矣, /css/** = anon 配置.

閱讀全文

與filter不過濾靜態資源相關的資料

熱點內容
愛惠浦復合濾芯怎麼拆 瀏覽:528
紅外光譜樹脂 瀏覽:786
平涼造紙廠污水處理設備哪裡有 瀏覽:698
sg3樹脂與sg5 瀏覽:157
B48N固體樹脂 瀏覽:485
樹脂模片用在什麼地方 瀏覽:26
水稀釋性丙烯酸樹脂的制備 瀏覽:997
減壓蒸餾能夠除去微量溶劑嗎 瀏覽:17
購買的桶裝蒸餾水保質期是多久 瀏覽:64
全屋凈水怎麼做的 瀏覽:556
皮革污水處理生化池出水紅色 瀏覽:878
污水處理廠工藝廠長崗位職責 瀏覽:666
學校雨污水施工視頻 瀏覽:812
自來水水垢去除 瀏覽:162
污水處理廠水量計量 瀏覽:261
立升凈水前景如何 瀏覽:664
生活污水反應池作用 瀏覽:29
萬和凈水器怎麼樣啊 瀏覽:127
變速箱油濾芯堵塞怎麼辦 瀏覽:634
爽力廚房凈水器多少錢一台 瀏覽:27