IllegalVistorFilter2018-07-09

public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException {

System.out.println("IllegalVisitorFilter doFilter() is launched.");

HttpServletRequest request=(HttpServletRequest) req;

HttpServletResponse response=(HttpServletResponse) resp;

String url=request.getRequestURI();

String methodName=request.getParameter("method");

?url=url+"_"+methodName;

System.out.println(url); // request路徑中是否包含login字符串?目的是判斷是否需要攔截? if(url.contains("login"))

{ chain.doFilter(request, response); return; }

?System.out.println("**********************");

Object object = request.getSession().getAttribute("username");

if(object==null){

System.out.println("當(dāng)前沒有登錄哦,退回登錄界面!");

response.sendRedirect(request.getContextPath()+"/login.jsp"); }

?else{

System.out.println(object.toString());

?chain.doFilter(request, response); }

?}

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 本文包括:1、Filter簡介2、Filter是如何實(shí)現(xiàn)攔截的?3、Filter開發(fā)入門4、Filter的生命周期...
    廖少少閱讀 7,503評(píng)論 3 56
  • Spring Cloud為開發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見模式的工具(例如配置管理,服務(wù)發(fā)現(xiàn),斷路器,智...
    卡卡羅2017閱讀 136,506評(píng)論 19 139
  • 監(jiān)聽器(listener) 監(jiān)聽器簡介 :監(jiān)聽器就是一個(gè)實(shí)現(xiàn)特定接口的普通java程序,這個(gè)程序?qū)iT用于監(jiān)聽另一個(gè)...
    奮斗的老王閱讀 2,671評(píng)論 0 53
  • 高:我的問題是想問曹總的,剛才您說的非??犊ぐ?,說作為專利權(quán)人投入了很多但是沒有得到回報(bào)。先說我的想法,如果我有...
    唐屠閱讀 736評(píng)論 0 0
  • 弄意一年,忽然閑下,還賤兮兮的略感不適??赡苁沁@月太忙的緣故。離開上家創(chuàng)業(yè)公司,重新加入了新的創(chuàng)業(yè)團(tuán)隊(duì),繼續(xù)掙扎在...
    韓利閱讀 1,897評(píng)論 1 52

友情鏈接更多精彩內(nèi)容