转码
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() { } }