Home Database Mysql Tutorial 六、访问CGI变量_MySQL

六、访问CGI变量_MySQL

Jun 01, 2016 pm 02:07 PM
cgi servlet variable character access ask path part

6.1 CGI变量概述

   如果你是从传统的CGI编程转而学习Java Servlet,或许已经习惯了“CGI变量”这一概念。CGI变量汇集了各种有关请求的信息:

部分来自HTTP请求命令和请求头,例如Content-Length头;
部分来自Socket本身,例如主机的名字和IP地址;
也有部分与服务器安装配置有关,例如URL到实际路径的映射。
   6.2 标准CGI变量的Servlet等价表示

   下表假定request对象是提供给doGet和doPost方法的HttpServletRequest类型对象。 CGI变量  含义  从doGet或doPost访问  
AUTH_TYPE  如果提供了Authorization头,这里指定了具体的模式(basic或者digest)。  request.getAuthType()  
CONTENT_LENGTH  只用于POST请求,表示所发送数据的字节数。  严格地讲,等价的表达方式应该是String.valueOf(request.getContentLength())(返回一个字符串)。但更常见的是用request.getContentLength()返回含义相同的整数。  

CONTENT_TYPE  如果指定的话,表示后面所跟数据的类型。  request.getContentType()  
DOCUMENT_ROOT  与http://host/对应的路径。  getServletContext().getRealPath("/")
注意低版本Servlet规范中的等价表达方式是request.getRealPath("/")。

HTTP_XXX_YYY  访问任意HTTP头。  request.getHeader("Xxx-Yyy")  
PATH_INFO  URL中的附加路径信息,即URL中Servlet路径之后、查询字符串之前的那部分。  request.getPathInfo()  
PATH_TRANSLATED  映射到服务器实际路径之后的路径信息。  request.getPathTranslated()  
QUERY_STRING  这是字符串形式的附加到URL后面的查询字符串,数据仍旧是URL编码的。在Servlet中很少需要用到未经解码的数据,一般使用getParameter访问各个参数。  request.getQueryString()  
REMOTE_ADDR  发出请求的客户机的IP地址。  request.getRemoteAddr()  
REMOTE_HOST  发出请求的客户机的完整的域名,如java.sun.com。如果不能确定该域名,则返回IP地址。  request.getRemoteHost()  
REMOTE_USER  如果提供了Authorization头,则代表其用户部分。它代表发出请求的用户的名字。  request.getRemoteUser()  
REQUEST_METHOD  请求类型。通常是GET或者POST。但偶尔也会出现HEAD,PUT, DELETE,OPTIONS,或者 TRACE.  request.getMethod()  
SCRIPT_NAME  URL中调用Servlet的那一部分,不包含附加路径信息和查询字符串。  request.getServletPath()  
SERVER_NAME  Web服务器名字。  request.getServerName()  

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Different uses of slashes and backslashes in file paths Different uses of slashes and backslashes in file paths Feb 26, 2024 pm 04:36 PM

A file path is a string used by the operating system to identify and locate a file or folder. In file paths, there are two common symbols separating paths, namely forward slash (/) and backslash (). These two symbols have different uses and meanings in different operating systems. The forward slash (/) is a commonly used path separator in Unix and Linux systems. On these systems, file paths start from the root directory (/) and are separated by forward slashes between each directory. For example, the path /home/user/Docume

What are instance variables in Java What are instance variables in Java Feb 19, 2024 pm 07:55 PM

Instance variables in Java refer to variables defined in the class, not in the method or constructor. Instance variables are also called member variables. Each instance of a class has its own copy of the instance variable. Instance variables are initialized during object creation, and their state is saved and maintained throughout the object's lifetime. Instance variable definitions are usually placed at the top of the class and can be declared with any access modifier, which can be public, private, protected, or the default access modifier. It depends on what we want this to be

How to get variables from PHP method using Ajax? How to get variables from PHP method using Ajax? Mar 09, 2024 pm 05:36 PM

Using Ajax to obtain variables from PHP methods is a common scenario in web development. Through Ajax, the page can be dynamically obtained without refreshing the data. In this article, we will introduce how to use Ajax to get variables from PHP methods, and provide specific code examples. First, we need to write a PHP file to handle the Ajax request and return the required variables. Here is sample code for a simple PHP file getData.php:

What is the difference in the 'My Computer' path in Win11? Quick way to find it! What is the difference in the 'My Computer' path in Win11? Quick way to find it! Mar 29, 2024 pm 12:33 PM

What is the difference in the "My Computer" path in Win11? Quick way to find it! As the Windows system is constantly updated, the latest Windows 11 system also brings some new changes and functions. One of the common problems is that users cannot find the path to "My Computer" in Win11 system. This was usually a simple operation in previous Windows systems. This article will introduce how the paths of "My Computer" are different in Win11 system, and how to quickly find them. In Windows1

Correct way to display Chinese characters in matplotlib Correct way to display Chinese characters in matplotlib Jan 13, 2024 am 11:03 AM

Correctly displaying Chinese characters in matplotlib is a problem often encountered by many Chinese users. By default, matplotlib uses English fonts and cannot display Chinese characters correctly. To solve this problem, we need to set the correct Chinese font and apply it to matplotlib. Below are some specific code examples to help you display Chinese characters correctly in matplotlib. First, we need to import the required libraries: importmatplot

How to solve the problem of inaccessibility after Tomcat deploys war package How to solve the problem of inaccessibility after Tomcat deploys war package Jan 13, 2024 pm 12:07 PM

How to solve the problem that Tomcat cannot successfully access the war package after deploying it requires specific code examples. As a widely used Java Web server, Tomcat allows developers to package their own developed Web applications into war files for deployment. However, sometimes we may encounter the problem of being unable to successfully access the war package after deploying it. This may be caused by incorrect configuration or other reasons. In this article, we'll provide some concrete code examples that address this dilemma. 1. Check Tomcat service

Mind map of Python syntax: in-depth understanding of code structure Mind map of Python syntax: in-depth understanding of code structure Feb 21, 2024 am 09:00 AM

Python is widely used in a wide range of fields with its simple and easy-to-read syntax. It is crucial to master the basic structure of Python syntax, both to improve programming efficiency and to gain a deep understanding of how the code works. To this end, this article provides a comprehensive mind map detailing various aspects of Python syntax. Variables and Data Types Variables are containers used to store data in Python. The mind map shows common Python data types, including integers, floating point numbers, strings, Boolean values, and lists. Each data type has its own characteristics and operation methods. Operators Operators are used to perform various operations on data types. The mind map covers the different operator types in Python, such as arithmetic operators, ratio

What are the application scenarios of Java Servlet? What are the application scenarios of Java Servlet? Apr 17, 2024 am 08:21 AM

JavaServlet can be used for: 1. Dynamic content generation; 2. Data access and processing; 3. Form processing; 4. File upload; 5. Session management; 6. Filter. Example: Create a FormSubmitServlet to handle form submission, taking name and email as parameters, and redirecting to success.jsp.

See all articles