有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java使用ServletRegistration可以配置什么。动态

这是一个关于Java认证1Z0-899的问题
我必须选择两个答案

问题是:

ServletRegistration.Dynamic can be used to configure:

A) Filter mappings
B) add init params
C) set asyncSupported to true
D) add Listeners


我认为这应该是正确的B,C。但我的文字说的是A,B。
谁是对的


共 (2) 个答案

  1. # 1 楼答案

    A)要配置过滤器映射,可以使用 FilterRegistration.Dynamic.addMappingForServletNames(java.util.EnumSet dispatcherTypes, boolean b, java.lang.String... strings)FilterRegistration.Dynamic.(java.util.EnumSet dispatcherTypes, boolean b, java.lang.String... strings)

    B)用于添加initParams-ServletRegistration.Dynamic.setInitParameter(java.lang.String s, java.lang.String s1)ServletRegistration.Dynamic. setInitParameters(java.util.Map stringStringMap)

    C)将asyncSupported设置为true ServletRegistration.Dynamic.setAsyncSupported(boolean b)

    D)添加带有ServletContext.addListener(T t)的侦听器

    这意味着正确的答案是B和C

  2. # 2 楼答案

    从Servlet Context 3.0的规范第31页:

    4.4.1 Programmatically adding and configuring Servlets

    The ability to programmatically add a servlet to a context is useful for framework developers. For example a framework could declare a controller servlet using this method. The return value of this method is a ServletRegistration or a ServletRegistration.Dynamic object which further allows you to setup the other parameters of the servlet like init-params, url-mappings etc. There are three overloaded versions of the method as described below.

    可以看到,它们提到了init参数和url映射

    因此,也许是谁创建了这个问题/答案,请选择以下文本:),以及ServletRegistration。Dynamic用于以编程方式配置由Servlet上下文创建或添加的Servlet,如添加映射、init param和设置安全约束属性

    谢谢!