如果您不太喜欢 xml 配置,而是特别喜欢注释,那么 Servlets API 也可以。 您可以使用[`@WebServlet`](https://docs.oracle.com/javaee/6/api/javax/servlet/annotation/WebServlet.html"WebServlet")注释,如下例所示,然后您无需在`web.xml`中进行任何输入。 **容器将自动将您的 servlet 注册到运行时,并像往常一样处理它**。
如果您不太喜欢 xml 配置,而是特别喜欢注解,那么 Servlets API 也可以。 您可以使用[`@WebServlet`](https://docs.oracle.com/javaee/6/api/javax/servlet/annotation/WebServlet.html"WebServlet")注解,如下例所示,然后您无需在`web.xml`中进行任何输入。 **容器将自动将您的 servlet 注册到运行时,并像往常一样处理它**。
```java
packagecom.howtodoinjava.servlets;
...
...
@@ -459,7 +459,7 @@ Web 过滤器对于预处理请求和访问给定 URL 时调用某些功能很
在以前的帖子中,我们了解了 [helloworld 应用](//howtodoinjava.com/struts-2/struts-2-hello-world-with-annotations/"Struts2 hello world with annotations")和[设置 Struts2 应用](//howtodoinjava.com/struts-2/how-to-correctly-set-result-path-in-struts-2/"How to correctly set result path in Struts2")的结果路径。 现在,在这篇文章中,我将举一个使用注释的自定义或用户定义的拦截器配置示例。
在以前的帖子中,我们了解了 [helloworld 应用](//howtodoinjava.com/struts-2/struts-2-hello-world-with-annotations/"Struts2 hello world with annotations")和[设置 Struts2 应用](//howtodoinjava.com/struts-2/how-to-correctly-set-result-path-in-struts-2/"How to correctly set result path in Struts2")的结果路径。 现在,在这篇文章中,我将举一个使用注解的自定义或用户定义的拦截器配置示例。
`@XmlRootElement`将类或[枚举类型](https://howtodoinjava.com/java/enum/guide-for-understanding-enum-in-java/)映射到 XML 元素。 当使用`@XmlRootElement`注解注释顶级类或枚举类型时,则其值在 XML 文档中表示为 XML 元素。
`@XmlRootElement`将类或[枚举类型](https://howtodoinjava.com/java/enum/guide-for-understanding-enum-in-java/)映射到 XML 元素。 当使用`@XmlRootElement`注解来注解顶级类或枚举类型时,则其值在 XML 文档中表示为 XML 元素。