简体   繁体   English

为什么javax.servlet包仅作为应用程序服务器的一部分分发?

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

I'm not new to servlets. 我对servlet并不陌生。 But I'm still curious: why javax.servlet package isn't distributed on its own? 但是我仍然很好奇:为什么javax.servlet包没有javax.servlet分发? 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. Servlet是规范和API。 If you want the JAR, download it from the spec site Servlet Spec 3.0 . 如果需要JAR,请从规范站点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. 可以通过一些jar使用servlet API,您可以根据需要使用它。 On maven it is here . 在Maven上就在这里 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. Servlet仅在Web应用程序的上下文中才真正相关,这就是为什么存在Servlet容器的原因。 They are the implementation. 它们是实现。 Take a look at all the work the container does before a request reaches the servlet: Tomcat Sequence Diagram . 看一看容器在请求到达servlet之前所做的所有工作: Tomcat Sequence Diagram

Servlets like other Java EE technology like EJB are Specification from JSR (Java Specification Requests) from Java Community Process Program 像EJB之类的其他Java EE技术一样,Servlet是Java Community Process Program的 JSR规范(Java Specification Requests)

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 应用服务器供应商有责任根据发布的规范提供实现。在这种情况下-对于Servlet 2.5-对于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 . Sun /现在Oracle确实单独发布了javax.servlet软件包,您可以从Maven存储库下载它,也可以在任何J2ee投诉应用程序服务器/ Web容器的lib文件夹中找到它。 ie for Tomcat its available in TOMCAT_HOMEDIR/lib/servlet-api 即对于Tomcat,它在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 . 因此对于developing and compiling , this jar is sufficientneed the Application server only when you want to actually deploy your application时才need the Application server only when you want to actually deploy your application

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

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