Java – how to use the web XML contains additional configuration files
I need to define many servlets, but I don't want to use them on the web Write all configurations in XML
I can define some servlet configuration files and include them in the web XML? Or is there any other way to web Split XML into multiple files?
Solution
The servlet 3.0 specification provides a new annotation @ webservlet, which can be used to declare servlets in code without web xml. For details, see 8.1.1 of servlet 3.0 specification Section 1 and view Javadoc
@WebServlet("/myServlet") public class MyServlet extends HttpServlet { //... }
In addition, servlet 3.0 introduces the concept of Web fragment, which solves the problem of integrating web The second problem of splitting XML into multiple files These fragments can contain part (or all) of the web deployment descriptor by including meta-inf / Web fragment.xml in the jar file in the WEB-INF / lib directory of the web module XML files and / or servlet comments For details, see Section 8.2 of servlet 3.0 specification