資源描述:
《filter寫的登陸過濾器.doc》由會員上傳分享,免費在線閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫。
1、java文件代碼:packagecom.yang.juping;importjava.io.IOException;importjavax.servlet.Filter;importjavax.servlet.FilterChain;importjavax.servlet.FilterConfig;importjavax.servlet.ServletException;importjavax.servlet.ServletRequest;importjavax.servlet.ServletResponse;importjavax.servlet.http.HttpServlet;imp
2、ortjavax.servlet.http.HttpServletRequest;importjavax.servlet.http.HttpServletResponse;publicclassJupingimplementsFilter{FilterConfigconfig=null;publicvoidinit(FilterConfigconfig)throwsServletException{this.config=config;}publicvoiddoFilter(ServletRequestrequest,ServletResponseresponse,FilterChainc
3、hain)throwsIOException,ServletException{System.out.println(1111);HttpServletRequestreq=(HttpServletRequest)request;//把request,response轉(zhuǎn)換為HttpServletRequestHttpServletResponseres=(HttpServletResponse)response;res.sendRedirect("index.jsp");//指定要跳轉(zhuǎn)的頁面}publicvoiddestroy(){}}在web.xml寫入//當(dāng)訪問/index.jsp時,
4、就轉(zhuǎn)向com.yang.juping.Jupingjupcom.yang.juping.Jupingjup/index.jsp2:網(wǎng)上找的還沒用過。java代碼一、使瀏覽器不緩存頁面的過濾器importjavax.servlet.*;importjavax.servlet.h
5、ttp.HttpServletResponse;importjava.io.IOException;/***用于的使Browser不緩存頁面的過濾器*/publicclassForceNoCacheFilterimplementsFilter{publicvoiddoFilter(ServletRequestrequest,ServletResponseresponse,FilterChainfilterChain)throwsIOException,ServletException{((HttpServletResponse)response).setHeader("Cache-Cont
6、rol","no-cache");((HttpServletResponse)response).setHeader("Pragma","no-cache");((HttpServletResponse)response).setDateHeader("Expires",-1);filterChain.doFilter(request,response);}publicvoiddestroy(){}publicvoidinit(FilterConfigfilterConfig)throwsServletException{}}二、檢測用戶是否登陸的過濾器importjavax.servle
7、t.*;importjavax.servlet.http.HttpServletRequest;importjavax.servlet.http.HttpServletResponse;importjavax.servlet.http.HttpSession;importjava.util.List;importjava.util.ArrayList;importjava.util.StringTokenizer;imp