简体   繁体   English

servlet是编写Java Web应用程序的唯一方法

[英]Are servlets the only way to write a Java Web Application

servlet是用Java编写Web应用程序的唯一方法吗?

No. Servlets are just the most convenient way to write a Web application in Java. 不可以.Servlet是用Java编写Web应用程序的最便捷方式。 If you think about it: what is a Web application? 如果你考虑一下:什么是Web应用程序? Quite simply it is an application that can receive an HTTP request and send back an HTTP response. 很简单,它是一个可以接收HTTP请求并发回HTTP响应的应用程序。 Common models for achieving this are: 实现这一目标的常见模型是:

  1. To use some kind of wrapper that invokes a script for each request. 使用某种为每个请求调用脚本的包装器。 This was the first model and has a standard called CGI (Common Gateway Interface). 这是第一个型号,有一个名为CGI (通用网关接口)的标准。 The wrapper in this case is a Web server; 在这种情况下,包装器是Web服务器; or 要么
  2. To have persistent code within such a wrapper that can service HTTP requests (rather than being transient like CGI scripts). 在这样的包装器中拥有持久性代码,可以为HTTP请求提供服务(而不是像CGI脚本那样是瞬态的)。

There are variations upon this theme (eg FastCGI for (1)). 这个主题有变化(例如(1)的FastCGI )。 Servlets are an example of (2). Servlet是(2)的一个例子。 The reason 99% of all Java Web applications and frameworks use servlets is because servlets are standard (they have a specification endorsed by Sun and a reference implementation ) and they're so low-level that pretty much whatever you want can be built on top of them. 99%的Java Web应用程序和框架使用servlet的原因是因为servlet是标准的(它们有Sun认可的规范和参考实现 )而且它们的级别很低,几乎无论你想要什么都可以构建在顶层他们

That servlets are most convenient way to write Web apps in Java is arguable. servlet是用Java编写Web应用程序最方便的方法。 They certainly have been around for a long time, but there are alternatives; 他们肯定已经存在了很长时间,但也有其他选择; take a look at restlets for example: http://www.restlet.org/ 看一下restlets,例如: http//www.restlet.org/

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

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