如何仅对http post方法应用servletfilter
在我的应用程序中,我想应用一些filter,但我不希望所有的请求都必须转到该filter。 这将是一个性能问题,因为我们已经有了一些其他的filter。
我希望我的filter仅适用于HTTP POST方法..有什么办法吗?
请帮我解决这个问题。
谢谢Kiran
没有现成的function。 Filter
在应用于所有HTTP方法时没有任何开销。 但是,如果您在Filter
代码中有一些具有开销的逻辑,则不应该将该逻辑应用于不需要的HTTP方法。
以下是示例代码:
public class HttpMethodFilter implements Filter { public void init(FilterConfig filterConfig) throws ServletException { } public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException { HttpServletRequest httpRequest = (HttpServletRequest) request; if(httpRequest.getMethod().equalsIgnoreCase("POST")){ } filterChain.doFilter(request, response); } public void destroy() { } }