課程
/后端開發(fā)
/Java
/Java Web開發(fā)技術(shù)應(yīng)用——過濾器
哪位童鞋知道在3.0版本用注解怎么配置noLoginPaths嗎?
2018-03-26
源自:Java Web開發(fā)技術(shù)應(yīng)用——過濾器 6-1
正在回答
過濾器并沒有noLogginPaths這個(gè)參數(shù), 要是想實(shí)現(xiàn)只能在過濾器的初始化時(shí)候設(shè)置上哪些不要過濾。下面是練習(xí)寫的一個(gè)demo
@WebFilter(urlPatterns = { "*.jsp" },initParams ={@WebInitParam(name = "myNoLoginPaths", value = "/cc.jsp;/dd.jsp") })public class MyFilter implements Filter {?? ?private FilterConfig config; ??? ??? ?@Override?? ?public void destroy() {?? ?}?? ?@Override?? ?public void doFilter(ServletRequest arg0, ServletResponse arg1,?? ??? ??? ?FilterChain arg2) throws IOException, ServletException {?? ??? ?HttpServletRequest request = (HttpServletRequest) arg0; ??? ??? ??? ??? ?//判斷是否需要攔截?? ??? ?boolean needFilte = true;?? ??? ?//獲取 不攔截的路徑列表?? ??? ?String noLoginPaths = config.getInitParameter("myNoLoginPaths"); ??? ??? ?if(noLoginPaths!= null && !"".equals(noLoginPaths)){?? ??? ??? ?String[] strings = noLoginPaths.split(";");?? ??? ??? ?for (String tempUrl : strings) {?? ??? ??? ??? ?if(request.getRequestURI().indexOf(tempUrl)!=-1 ){ ??? ??? ??? ??? ??? ?needFilte = false;?? ??? ??? ??? ??? ?break;?? ??? ??? ??? ?} ?? ??? ??? ??? ??? ??? ??? ?}?? ??? ??? ??? ??? ?}?? ??? ??? ??? ??? ??? ?if(needFilte){?? ??? ??? ?//具體的攔截處理邏輯?? ??? ??? ?System.out.println("過濾器處理業(yè)務(wù)"+request.getRequestURI());?? ??? ?}?? ??? ??? ??? ?arg2.doFilter(arg0, arg1);?? ??? ??? ??? ??? ??? ??? ??? ??? ?}?? ?@Override?? ?public void init(FilterConfig arg0) throws ServletException {?? ??? ?config = arg0;?? ?}}
qq_與贈(zèng)_03193390 提問者
好厲害呀
在web.xml里面有一個(gè)init_param屬性:
<init-param>
? <param-name>encoding</param-name>
? <param-value>UTF-8</param-value>
? </init-param>
? <init-param>
? <param-name>ignoreExistEncoding</param-name>
? <param-value>true</param-value>
用這個(gè)配置就可以實(shí)現(xiàn)獲取屬性的
舉報(bào)
本課程主要是從實(shí)際生活當(dāng)中的過濾器入手,詳細(xì)講解了Java Web過濾器
3 回答2014版本可以用嗎
3 回答Web Application 版本怎么改?
1 回答在使用servlet3.0是dispatchtype設(shè)置為error,如何通過注解的方式為他配置 錯(cuò)誤頁面
4 回答web 3.0 怎么添加過濾網(wǎng)頁
1 回答Myeclipse10.7.1在哪里下載啊?我用的2014年版本的,在這節(jié)課運(yùn)行根本不行,可以給一個(gè)10.7.1的鏈接嗎
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號(hào)-11 京公網(wǎng)安備11010802030151號(hào)
購(gòu)課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號(hào)
2018-03-27
過濾器并沒有noLogginPaths這個(gè)參數(shù), 要是想實(shí)現(xiàn)只能在過濾器的初始化時(shí)候設(shè)置上哪些不要過濾。下面是練習(xí)寫的一個(gè)demo
@WebFilter(urlPatterns = { "*.jsp" },initParams ={@WebInitParam(name = "myNoLoginPaths", value = "/cc.jsp;/dd.jsp") })
public class MyFilter implements Filter {
?? ?private FilterConfig config; ?
?? ?
?? ?@Override
?? ?public void destroy() {
?? ?}
?? ?@Override
?? ?public void doFilter(ServletRequest arg0, ServletResponse arg1,
?? ??? ??? ?FilterChain arg2) throws IOException, ServletException {
?? ??? ?HttpServletRequest request = (HttpServletRequest) arg0; ?
?? ??? ?
?? ??? ?//判斷是否需要攔截
?? ??? ?boolean needFilte = true;
?? ??? ?//獲取 不攔截的路徑列表
?? ??? ?String noLoginPaths = config.getInitParameter("myNoLoginPaths"); ?
?? ??? ?if(noLoginPaths!= null && !"".equals(noLoginPaths)){
?? ??? ??? ?String[] strings = noLoginPaths.split(";");
?? ??? ??? ?for (String tempUrl : strings) {
?? ??? ??? ??? ?if(request.getRequestURI().indexOf(tempUrl)!=-1 ){ ?
?? ??? ??? ??? ??? ?needFilte = false;
?? ??? ??? ??? ??? ?break;
?? ??? ??? ??? ?}
?? ??? ??? ??? ?
?? ??? ??? ?}
?? ??? ??? ?
?? ??? ?}?? ??? ?
?? ??? ?
?? ??? ?if(needFilte){
?? ??? ??? ?//具體的攔截處理邏輯
?? ??? ??? ?System.out.println("過濾器處理業(yè)務(wù)"+request.getRequestURI());
?? ??? ?}
?? ??? ?
?? ??? ?arg2.doFilter(arg0, arg1);
?? ??? ?
?? ??? ?
?? ??? ?
?? ??? ?
?? ?}
?? ?@Override
?? ?public void init(FilterConfig arg0) throws ServletException {
?? ??? ?config = arg0;
?? ?}
}
2018-07-27
好厲害呀
2018-06-07
在web.xml里面有一個(gè)init_param屬性:
<init-param>
? <param-name>encoding</param-name>
? <param-value>UTF-8</param-value>
? </init-param>
? <init-param>
? <param-name>ignoreExistEncoding</param-name>
? <param-value>true</param-value>
? </init-param>
用這個(gè)配置就可以實(shí)現(xiàn)獲取屬性的