ackage com.puckasoft.xjgsfood.web.filter;import java.io.IOException;import java.io.PrintWriter;import javax.servlet.Filter;import javax.servlet.FilterChain;import javax.servlet.FilterConfig;import javax.servlet.ServletException;import javax.servlet.ServletRequest;import javax.servlet.ServletResponse;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import com.puckasoft.xjgsfood.util.CommonUtils;import com.puckasoft.xjgsfood.util.Constants;public class LoginUserFilter implements Filter { public void destroy() { } public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { request.setCharacterEncoding("UTF-8"); response.setCharacterEncoding("UTF-8"); HttpServletRequest req = (HttpServletRequest)request; HttpServletResponse resp = (HttpServletResponse)response; Object obj = req.getSession().getAttribute("user的key"); if(obj == null){ request.setAttribute("loginError", "您还没有登录。
不能使用此功能!"); request.getRequestDispatcher("/***").forward(request, response); } chain.doFilter(request, response); } public void init(FilterConfig arg0) throws ServletException { } }。