java 过滤器的配置

package fiters; import javax.servlet.Filter; import javax.servlet.*; import java.io.IOException; import javax.servlet.http.*; public class ogFiters implements Filter{ public void init(FilterConfig parm1) throws ServletException { // TODO: Add your code here } public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest hsRequest = (HttpServletRequest)request; HttpServletResponse hsResponse = (HttpServletResponse)response; request.setCharacterEncoding("gb2312"); response.setCharacterEncoding("gb2312"); /*HttpSession session = hsRequest.getSession(); //没登录 if(session.getAttribute("userName")==null) { String uri = hsRequest.getRequestURI(); //请求登录页面 if(uri.endsWith("login.html")|| uri.endsWith("login")) { chain.doFilter(request,response); } //请求其它页面 else { hsResponse.sendRedirect("login.html"); } } //登录成功 else { chain.doFilter(request,response); }*/ chain.doFilter(request,response); } public void destroy() { // TODO: Add your code here } } loginfilter fiters.ogFiters loginfilter *.do

你可能感兴趣的:(java)