简体   繁体   中英

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? For example i am currently working with tomcat 8 and i am using the restful jersey framework. 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? Also can someone tell where i can find the java ee web.xml specification/documentation?

thanks

Deployment descriptors are part of the Java Servlet specification.

You can find the 3.1 spec here JSR340

check the final release at https://www.jcp.org/en/jsr/detail?id=340

servlet-class provides the fully qualified Java class name of this endpoint implementation. You specify the serlvet class name, eg com.stackoverflow.myweb.LoginSerlvet and this can be mapped to a url like /login. 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.). Also depends on your Servlets you might need to add used external libs. 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. 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). 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.

Do some tutorials for how to build Java servlet application and you will soon understand it better.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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