我不久就实现了用于身份验证的过滤器。我已经编写了类似于以下内容的代码:
public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain){ HttpServletResponse response=(HttpServletResponse) resp; boolean authenticated=false; // perform authentication if (authenticated) { chain.doFilter(req, response); } else { // don't continue the chain response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); response.setHeader("WWW-Authenticate", "BASIC realm="Your realm""); response.setContentType("what you need"); PrintWriter writer=response.getWriter(); // don't set content length , don't close }}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)