简体   繁体   English

Java web.xml<servlet-class> 标签和 web.xml 规范/文档

[英]Java web.xml <servlet-class> tag and web.xml Specification/Documentation

Can someone tell me what the usage of the servlet-class tag in the web.xml is?有人能告诉我 web.xml 中 servlet-class 标签的用法是什么吗? For example i am currently working with tomcat 8 and i am using the restful jersey framework.例如,我目前正在使用 tomcat 8,并且我正在使用 restful jersey 框架。 so why do you put this class: org.glassfish.jersey.servlet.ServletContainer in the servlet-class tag and not org.apache.catalina.servlets.DefaultServlet for the tomcat?那么为什么你把这个类:org.glassfish.jersey.servlet.ServletContainer 放在 servlet-class 标签中,而不是 org.apache.catalina.servlets.DefaultServlet 中的 tomcat? Also can someone tell where i can find the java ee web.xml specification/documentation?也有人能告诉我在哪里可以找到 java ee web.xml 规范/文档吗?

thanks谢谢

Deployment descriptors are part of the Java Servlet specification.部署描述符是 Java Servlet 规范的一部分。

You can find the 3.1 spec here JSR340你可以在这里找到 3.1 规范JSR340

check the final release at https://www.jcp.org/en/jsr/detail?id=340https://www.jcp.org/en/jsr/detail?id=340查看最终版本

servlet-class provides the fully qualified Java class name of this endpoint implementation. servlet-class提供此端点实现的完全限定 Java 类名。 You specify the serlvet class name, eg com.stackoverflow.myweb.LoginSerlvet and this can be mapped to a url like /login.您指定 serlvet 类名,例如 com.stackoverflow.myweb.LoginSerlvet,这可以映射到 /login 之类的 url。 This makes it easier to use in the web application, in your html etc. Whenever /login is requested the LoginServlet will run (depends on the HTTP type, if it is GET, POST etc.).这使得在 web 应用程序、html 等中更容易使用。每当 /login 被请求时,LoginServlet 将运行(取决于 HTTP 类型,如果它是 GET、POST 等)。 Also depends on your Servlets you might need to add used external libs.还取决于您的 Servlet,您可能需要添加使用过的外部库。 For example in your case you need the jersey libraries.例如,在您的情况下,您需要球衣库。 Check also the web.xml to set-up the servlet (servlet-class) and check the servlet-mapping.还要检查 web.xml 以设置 servlet(servlet 类)并检查 servlet 映射。 Why you need to add the ServletContainer and not the DefaultServlet is as you want to use the Rest Jersey, and whenever you call the mapped url (eg /rest/* it will run the jersey servlet).为什么需要添加 ServletContainer 而不是 DefaultServlet 是因为您想使用 Rest Jersey,并且每当您调用映射的 url(例如 /rest/* 它将运行 jersey servlet)。 I think you are a bit confused as you think the servlet-class is the class that will host all written servlets in your application, which is not.我认为您有点困惑,因为您认为 servlet-class 是将在您的应用程序中托管所有编写的 servlet 的类,但事实并非如此。

Do some tutorials for how to build Java servlet application and you will soon understand it better.做一些关于如何构建 Java servlet 应用程序的教程,你很快就会更好地理解它。

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

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