jsp登陸訪問跳轉

來源:互聯網
上載者:User
  1. 未登陸,禁止訪問任何頁面,自動跳轉到登陸頁

package com.catalogeasy.filter;<br />import java.io.IOException;<br />import javax.servlet.Filter;<br />import javax.servlet.FilterChain;<br />import javax.servlet.FilterConfig;<br />import javax.servlet.ServletException;<br />import javax.servlet.ServletRequest;<br />import javax.servlet.ServletResponse;<br />import javax.servlet.http.HttpServletRequest;<br />import javax.servlet.http.HttpServletResponse;<br />public class LoginFilter implements Filter {<br />public void destroy() {<br />// TODO Auto-generated method stub<br />}<br />public void doFilter(ServletRequest arg0, ServletResponse arg1,<br />FilterChain arg2) throws IOException, ServletException {<br />// TODO Auto-generated method stub<br />HttpServletRequest httprequest = (HttpServletRequest) arg0;<br />HttpServletResponse httpresponse = (HttpServletResponse) arg1;<br />String temp = httprequest.getServletPath();<br />if(httprequest.getSession().getAttribute("user")==null){<br />if("/jdom.do".equals(temp)||"/login.do".equals(temp)){<br />arg2.doFilter(arg0, arg1);<br />}else{<br />httpresponse.sendRedirect("/CatalogUser");<br />}<br />}else{<br />arg2.doFilter(arg0, arg1);<br />}<br />/*if(httprequest.getSession().getAttribute("user")==null&&((!"/jdom.do".equals(temp))||(!"/login.do".equals(temp)))){<br />httpresponse.sendRedirect("/CatalogUser/user/login.jsp");<br />}else{<br />arg2.doFilter(arg0, arg1);<br />}*/<br />}<br />public void init(FilterConfig arg0) throws ServletException {<br />// TODO Auto-generated method stub<br />}

 

      2.登陸後跳轉到請求頁面

import java.io.IOException;<br />import java.net.URLEncoder;<br />import javax.servlet.Filter;<br />import javax.servlet.FilterChain;<br />import javax.servlet.FilterConfig;<br />import javax.servlet.ServletException;<br />import javax.servlet.ServletRequest;<br />import javax.servlet.ServletResponse;<br />import javax.servlet.http.HttpServletRequest;<br />import javax.servlet.http.HttpServletResponse;<br />import com.ww.golf.bo.Player;<br />import com.ww.golf.util.ActionUtils;<br />public class LogFilter implements Filter {<br /> protected FilterConfig filterConfig;<br /> public void init(FilterConfig config) throws ServletException {<br /> this.filterConfig = config;<br /> }<br /> public void doFilter(ServletRequest srequest, ServletResponse sresponse,<br /> FilterChain chain) throws IOException, ServletException {<br /> HttpServletRequest request = (HttpServletRequest) srequest;<br /> HttpServletResponse response = (HttpServletResponse) sresponse;<br /> Player player = (Player) request.getSession().getAttribute(<br /> ActionUtils.PLAYER_OBJ_KEY);<br /> if (player == null) {<br /> StringBuffer sUrl = new StringBuffer("");<br /> if (request.getRequestURI() != null) {<br /> sUrl<br /> .append(URLEncoder.encode(request.getRequestURI(),<br /> "UTF-8"));<br /> }<br /> if (request.getQueryString() != null) {<br /> sUrl.append("?");<br /> sUrl.append(URLEncoder<br /> .encode(request.getQueryString(), "UTF-8"));<br /> }<br /> System.out.println("URL:" + sUrl);<br /> response.sendRedirect("../index.jsp?" + ActionUtils.GO_URI_KEY<br /> + "=" + sUrl.toString());<br /> } else {<br /> chain.doFilter(request, response);<br /> }<br /> }<br /> public void setFilterConfig(final FilterConfig filterConfig) {<br /> this.filterConfig = filterConfig;<br /> }<br /> public void destroy() {<br /> this.filterConfig = null;<br /> }<br />}<br />

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.