简体   繁体   中英

Why javax.servlet package is distributed only as part of application servers?

I'm not new to servlets. But I'm still curious: why javax.servlet package isn't distributed on its own? Why I need some application server installed before I can compile my code?

Short answer, it is distributed separately.

Servlets are a specification and an API. If you want the JAR, download it from the spec site Servlet Spec 3.0 .

Obviously if you want to actually deploy your application, you'll still need an implementation (ie a server).

The servlet API is available through some jar and you can do with it what you want. On maven it is here . You can compile the code without any application server but it probably won't do what you want. It is only an interface afterall

Servlets are only really relevant in the context of a Web Application and this is why Servlet Containers exist. They are the implementation. Take a look at all the work the container does before a request reaches the servlet: Tomcat Sequence Diagram .

Servlets like other Java EE technology like EJB are Specification from JSR (Java Specification Requests) from Java Community Process Program

The onus is on the Application Server vendor to provide the implementation based on the specifications released.In this case - for Servlet 2.5 - for Servlet 3.0

Sun / now Oracle does release the javax.servlet package separately and you can download it from Maven Repository also its available within the lib folder of any J2ee complaint application server/web container . ie for Tomcat its available in TOMCAT_HOMEDIR/lib/servlet-api

So for developing and compiling , this jar is sufficient , you would only need the Application server only when you want to actually deploy your application .

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