简体   繁体   English

Servlet映射。 Web.xml

[英]Servlet Mapping. Web.xml

In java web application is it possible to map servlets in files that are not "web.xml"? 在Java Web应用程序中,是否可以将servlet映射到非“ web.xml”文件中? I mean. 我的意思是。 I will need to map over a hundred servelts and web.xml would be dificult to deal with. 我将需要映射一百多个Servlts,并且很难处理web.xml。 Dividing the mappings in several file by cathegory would be great. 通过cathegory将映射划分为几个文件会很棒。

If there is some way please would you tell me how?. 如果有什么办法,请您告诉我如何?

Thank you very much. 非常感谢你。

Not sure about dividing web.xml file. 不确定是否要分割web.xml文件。 But you can achieve your task by defining your servlets through Java Annotations instead of defining them in web.xml. 但是您可以通过使用Java注释定义servlet而不是在web.xml中定义它们来完成任务。 The Servlet 3.0 specification provides a new annotation @WebServlet that can be used to declare your servlets. Servlet 3.0规范提供了一个新的@WebServlet批注,可用于声明您的servlet。

Yes. 是。 Servlet 3.0 provides Pluggability Feature which allows you to define web artifacts using: Servlet 3.0提供了可插入性功能 ,可使用以下功能定义Web工件:

  • Web Fragments . Web Fragments The libraries inside WEB-INF/lib can have META-INF/web-fragment.xml which can define part of full deployment descriptor. WEB-INF/lib可以具有META-INF/web-fragment.xml ,它可以定义完整部署描述符的一部分。
  • Annotations . Annotations You can define Servlet, Filters and Listeners using @WebServlet, @WebFilter and @WebListener annotation. 您可以使用@ WebServlet,@ WebFilter和@WebListener批注定义Servlet,过滤器和侦听器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM