Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/372.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 我们可以在spring中将servlet过滤器中的参数更改为拦截器吗_Java_Spring_Servlets_Spring Mvc_Interceptor - Fatal编程技术网

Java 我们可以在spring中将servlet过滤器中的参数更改为拦截器吗

Java 我们可以在spring中将servlet过滤器中的参数更改为拦截器吗,java,spring,servlets,spring-mvc,interceptor,Java,Spring,Servlets,Spring Mvc,Interceptor,我在一个jar文件中添加了一个过滤器作为参考 我的项目是《春天的自然》。我开发了一个web服务。我的过滤器“HelloWorld”应该拦截对此web服务的所有请求 此筛选器位于其中一个参考文件中 在这里,我想我会把它实现为拦截器 参考文件中的筛选器如下所示 public class HelloWorld implements Filter { private static final Logger _logger = Logger.getLogger(HelloWorld.class.getNa

我在一个jar文件中添加了一个过滤器作为参考

我的项目是《春天的自然》。我开发了一个web服务。我的过滤器“HelloWorld”应该拦截对此web服务的所有请求

此筛选器位于其中一个参考文件中

在这里,我想我会把它实现为拦截器

参考文件中的筛选器如下所示

public class HelloWorld implements Filter {
private static final Logger _logger = Logger.getLogger(HelloWorld.class.getName());

  protected String name = null;

  public HelloWorld()
  {
  }

  public HelloWorld(String name) {
    this.name = name;
  }

    public void doFilter(ServletRequest req, ServletResponse res,
            FilterChain chain) throws IOException, ServletException {

        HttpServletRequest request = (HttpServletRequest) req;

        PrintWriter out = response.getWriter();
        out.println("Hello "+name);     
        chain.doFilter(req, res);
    }
    public void init(FilterConfig config) throws ServletException {

        //Get init parameter
        String testParam = config.getInitParameter("test");

        //Print the init parameter
        System.out.println("test param: " + testParam);
    }
    public void destroy() {
        //add code to release any resource
    }

    //some other methods as well 
}
实现这一点的最佳方式是什么。由于应用程序中的限制,我无法在web.xml中配置筛选器

我们是否可以直接将这个HelloWorld过滤器作为拦截器的引用,使其行为类似于拦截器。 我们可以在spring中将此过滤器更改为拦截器,并在spring.xml中进行配置,而不必更改功能

如果我的问题很简单,我道歉


谢谢。

“由于我的应用程序中的限制”,具体哪一个限制?如果您的目标是与Servlet 3.0兼容的容器,那么您也可以只使用
@WebFilter
注释。@BalusC。我必须仅在我的spring.xml中将我的过滤器配置为bean。我无法在web.xml中配置它。我认为这是一个限制。为了澄清这一点,你想把这个过滤器重新实现到Spring拦截器中吗?@Sudhakar。对此筛选器已存在于一个引用文件中。我不能改变它。我可以像拦截器一样使用它吗。