servlet简介
Servlet简介 (Introduction to Servlet)
Servlet Technology is used to create web applications. Servlet technology uses Java language to create web applications.
Servlet技术用于创建Web应用程序。 Servlet技术使用Java语言创建Web应用程序。
Web applications are helper applications that resides at web server and build dynamic web pages. A dynamic page could be anything like a page that randomly chooses picture to display or even a page that displays the current time.
Web应用程序是驻留在Web服务器上并构建动态Web页面的帮助程序。 动态页面可以是随机选择要显示图片的页面,甚至可以显示当前时间的页面。
As Servlet Technology uses Java, web applications made using Servlet are Secured, Scalable and Robust.
由于Servlet Technology使用Java,因此使用Servlet制作的Web应用程序具有安全性 , 可扩展性和鲁棒性 。
CGI(通用网关接口) (CGI (Common Gateway Interface))
Before Servlets, CGI(Common Gateway Interface) programming was used to create web applications. Here's how a CGI program works :
在Servlets之前,CGI(通用网关接口)编程用于创建Web应用程序。 这是CGI程序的工作方式:
- User clicks a link that has URL to a dynamic page instead of a static page. 用户单击具有URL的链接,该链接指向动态页面而不是静态页面。
- The URL decides which CGI program to execute. URL决定执行哪个CGI程序。
- Web Servers run the CGI program in seperate OS shell. The shell includes OS enviroment and the process to execute code of the CGI program. Web服务器在单独的OS Shell中运行CGI程序。 该外壳程序包括OS环境和执行CGI程序代码的过程。
- The CGI response is sent back to the Web Server, which wraps the response in an HTTP response and send it back to the web browser. CGI响应被发送回Web服务器,后者将响应包装在HTTP响应中,然后将其发送回Web浏览器。
CGI程序的缺点 (Drawbacks of CGI programs)
- High resposne time because CGI programs execute in their own OS shell. 由于CGI程序在其自己的OS Shell中执行,因此可节省大量时间。
- CGI is not scalable. CGI不可扩展。
- CGI programs are not always secure or object-oriented. CGI程序并不总是安全的或面向对象的。
- It is Platform dependent. 它取决于平台。
Because of these disadvantages, developers started looking for better CGI solutions. And then Sun Microsystems developed Servlet as a solution over traditional CGI technology.
由于这些缺点,开发人员开始寻找更好的CGI解决方案。 然后,Sun Microsystems开发了Servlet作为基于传统CGI技术的解决方案。
使用Servlet的优点 (Advantages of using Servlets)
- Less response time because each request runs in a separate thread. 响应时间更少,因为每个请求都在单独的线程中运行。
- Servlets are scalable. Servlet是可伸缩的。
- Servlets are robust and object oriented. Servlet健壮且面向对象。
- Servlets are platform independent. Servlet与平台无关。
翻译自: https://www.studytonight.com/servlet/introduction-to-servlet.php
servlet简介