狂神说java超市管理系统filten

转码

package filter;


import javax.servlet.*;
import java.io.IOException;

public class FenCo implements Filter {


    public void init(FilterConfig filterConfig) throws ServletException {

    }

    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        servletRequest.setCharacterEncoding("utf8");
        servletResponse.setCharacterEncoding("utf8");
        filterChain.doFilter(servletRequest,servletResponse);
    }

    public void destroy() {

    }
}

登入拦截器

package filter;


import util.gongju;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class user implements Filter {
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain filterChain) throws IOException, ServletException {
       HttpServletRequest reqq = (HttpServletRequest) req;
        HttpServletResponse respp = (HttpServletResponse ) resp;
        Object attribute = reqq.getSession().getAttribute(gongju.USER_SESSION);
        if(attribute==null){

            respp.sendRedirect(reqq.getContextPath()+"/error.jsp");
        }
        filterChain.doFilter(req,resp);


    }

    public void destroy() {

    }
}

 

上一篇:Request请求参数中文乱码问题


下一篇:概率算法 go