package org.net.news.fileter;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class AdminFilter implements Filter{
public void init(FilterConfig filterConfig)throws ServletException{
}
public void doFilter(ServletRequest request,ServletResponse response,FilterChain chain)throws IOException,ServletException{
request.setCharacterEncoding("GBK");
HttpServletRequest req=(HttpServletRequest)request;
HttpServletResponse resp=(HttpServletResponse)response;
resp.setCharacterEncoding("GBK");
String name =(String)req.getSession(true).getAttribute("username");
if(name!=null)
{
chain.doFilter(request,response);
}else{
resp.sendRedirect("/news/admin.jsp");
}
}
public void destroy(){
}
}
用户是否登陆过滤器,如果不登陆的话则进入不了后台页面