如何在Web Filter中测试请求HTTP方法?

时间:2013-06-08 16:13:28

标签: java servlets filter

我有一个 WebFilter ,它充当所有JSP页面的过滤器:

"*.jsp"

如何测试请求是否为JSP过滤器的GET或POST?

1 个答案:

答案 0 :(得分:2)

您可以像这样检查过滤器:

       HttpServletRequest httpRequest = (HttpServletRequest) request;        
       if(httpRequest.getMethod().equalsIgnoreCase("POST")){
           System.out.println("This is a POST request");
       } else if (httpRequest.getMethod().equalsIgnoreCase("GET")) {
           System.out.println("This is a GET request");
       }