tomcat servlet JSP common gateway interface 公共网关接口

 

Tomcat主要充当servlet/JSP容器,不过它却有大量的功能可以与传统的Web服务器相媲美,对公共网关接口(Common Gateway Interface)的支持就是其中之一。

传统的Web服务器为了响应浏览器的请求,提供了运行外挂程序的一种方式,典型地用于处理基于Web的表单。这种机制叫做CGI。

CGI之所以称为通用,是因为它几乎可以调用所有编程或脚本语言:Perl、Python、awk、Unix Shell脚本,甚至还可以选择性地支持Java。

实际上,由于启动负荷过载,您可能不会将Java应用程序当成CGI来执行;而设计servlet规范的起因就是为了消除这种系统负载过载。

servlet几乎永远都比CGI高效,因为每当有人点击链接或按钮时候,并不会启动新的操作系统级进程。

 

 

[root@d3 apache-tomcat-7.0.90]# cat conf/tomcat-users.xml 
<?xml version='1.0' encoding='utf-8'?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<tomcat-users>
<!--
  NOTE:  By default, no user is included in the "manager-gui" role required
  to operate the "/manager/html" web application.  If you wish to use this app,
  you must define such a user - the username and password are arbitrary. It is
  strongly recommended that you do NOT use one of the users in the commented out
  section below since they are intended for use with the examples web
  application.
-->
<!--
  NOTE:  The sample user and role entries below are intended for use with the
  examples web application. They are wrapped in a comment and thus are ignored
  when reading this file. If you wish to configure these users for use with the
  examples web application, do not forget to remove the <!.. ..> that surrounds
  them. You will also need to set the passwords to something appropriate.
-->
<!--
  <role rolename="tomcat"/>
  <role rolename="role1"/>
  <user username="tomcat" password="<must-be-changed>" roles="tomcat"/>
  <user username="both" password="<must-be-changed>" roles="tomcat,role1"/>
  <user username="role1" password="<must-be-changed>" roles="role1"/>
-->
  <role rolename="admin"/>
  <user username="un" password="123" roles="admin"/>
</tomcat-users>
[root@d3 apache-tomcat-7.0.90]# 

  

在Java servlet出现之前,大多数Web应用程序都是以C/C++或Perl编写的。这些应用程序通常由多个静态HTML网页以及一些产生动态内容的CGI所构成。这些CGI脚本的编写过程可能与平台无关,不过这不是必要的

。同时,因为CGI是跨左右Web服务器品牌与实现的工业标准,所以CGI脚本可以写成独立于Web服务器实现的程序。事实上,某些CGI是这样处理的,而另一些则不是。CGI的最大问题是其设计本身会让他先天性执行缓慢,并无法扩充。

 

 

另一种产生动态网页内容的方式是使用Web服务器模块。例如,Apache http Web服务器可以在启动时执行动态可加载的模块。这些模块会响应预先配置的HTTP请求样式,并将动态网页内容送至HTTP的客户端/浏览器。

 

 

 

“通用网关接口”(CGI)是将Web服务器与自定义的Web应用程序挂钩的老标准,其主要用途是编写动态网页内容的脚本。一次,一半会把他成为“CGI脚本编写”(CGI scriprting),但其实也可以用C语言来编写CGI程序(对这样的程序,

我们一般不把它叫做脚本)。

 

所有对CGI脚本的HTTP请求,意味着操作系统都必须产生及执行新的进程,而且设计规则也会强制要求这样做。当Web服务器在大量网络负载下运行时,会启动和停止太多的进程,势必会造成服务器必须投入大部分资源以处理

启动和停止作业,而完成非HTTP请求。

 

posted @ 2018-08-04 10:05  papering  阅读(556)  评论(0编辑  收藏  举报