6.37. Ruby CGI method

发布时间 :2023-11-01 23:00:07 UTC      

The following is a list of methods for the CGI class:

Serial number

Method description

1

CGI::new([ level="query"]) Create a CGI object. Query can be the following value: query: no HTML generated output

Html3: HTML3.2

Html4: HTML4.0 Strict

Html4Tr: HTML4.0 Transitional

Html4Fr: HTML4.0 Frameset

2

CGI::escape( str) Escape strings using URL encoding

3

CGI::unescape( str) Decodes a string encoded through escape ().

4

CGI::escapeHTML( str) Encodes HTML special characters, including: & < >.

5

CGI::unescapeHTML( str) Decode HTML special characters, including: & < >.

6

CGI::escapeElement( str[, element...]) Encodes HTML special characters in the specified HTML element.

7

CGI::unescapeElement( str, element[, element...]) Decodes HTML special characters in the specified HTML element.

8

CGI::parse( query) Parses the query string and returns the key = “valuepair containing the hash.

9

CGI::pretty( string[, leader=" "]) Returns a neat HTML format. If leader is specified, it is written to the beginning of each line. The default value for leader is two spaces.

10

CGI::rfc1123_date( time) Format the time according to RFC-1123 (for example, Tue, 2 Jun 2008 00:00:00 GMT).

6.37.1. CGI instantiation method #

In the following example, we will CGI::new is assigned to the c variable, and the list of methods is as follows:

Serial number

Method description

1

c[ name] Returns an array containing the value of the corresponding field named name.

2

c.checkbox( name[, value[, check=false]]) c.checkbox( options) Returns the HTML string used to define the checkbox field. The attribute of the tag can be passed as a hash function as an argument.

3

c.checkbox_group( name, value...) c.checkbox_group( options) > thereturned HTML string is used to define checkbox groups. The attribute of the tag can be passed as a hash function as an argument.

4

c.file_field( name[, size=20[, max]]) c.file_field( options) Returns the HTML string that defines the file field.

5

c.form([ method="post"[, url]]) { ...} c.form( options) Returns the HTML string that defines the form form. If a code block is specified, itis output as the content of the form. The attribute of the tag can be passed as a hash function as an argument.

6

c.cookies Returns the CGI::Cookie object containing the key-value pairs in cookie.

7

c.header([ header]) Returns the information of the CGI header. If the header parameter is a hash, its key-value pair is used to create header information.

8

c.hidden( name[, value]) c.hidden( options) Returns a HTML string that defines a hidden field. The attribute of the tag can be passed as a hash function as an argument.

9

c.image_button( url[, name[, alt]]) c.image_button( options) Returns the HTML string that defines an image button. The attribute of the tag can be passed as a hash function as an argument.

10

c.keys Returns an array containing the field names of the form.

11

c.key?( name) c.has_key?( name) c.include?( name) Returns true if the form contains the specified field name.

12

c.multipart_form([ url[, encode]]) { ...} c.multipart_form( options) { ...} Returns the HTML string that defines a multimedia form (multipart). The attribute of the tag can be passed as a hash function as anargument.

13

c.out([ header]) { ...} Generate HTML and output. Use the string generated by the body of the page created by the output of the block.

14

c.params Returns a hash value containing the name and value of the form field.

15

c.params= hash Set to use field names and values.

16

c.password_field( name[, value[, size=40[, max]]]) c.password_field(options) Returns a HTML string that defines a password field. The attribute of the tag can be passed as a hash function as an argument.

17

c.popup_menu( name, value...) c.popup_menu( options) c.scrolling_list( name, value...) c.scrolling_list( options) Returns the HTML string that defines a pop-up menu. The attribute of the tagcan be passed as a hash function as an argument.

18

c.radio_button( name[, value[, checked=false]]) c.radio_button( options) Returns a HTML string that defines a radio field. The attribute of the tag can be passed as a hash function as an argument.

19

c.radio_group( name, value...) c.radio_group( options) Returns a HTML string that defines a group of radio buttons. The attribute of the tag can be passed as a hash function as an argument.

20

c.reset( name[, value]) c.reset( options) Returns the HTML string that defines a reset button. The attribute of the tag can be passed as a hash function as a parameter

21

c.text_field( name[, value[, size=40[, max]]]) c.text_field( options) Returns a HTML string that defines a text field. The attribute ofthe tag can be passed as a hash function as an argument.

22

c.textarea( name[, cols=70[, rows=10]]) { ...} c.textarea( options) { ...} Returns a HTML string that defines a textarea field. If a block is specified, the string output by the code block will be used as the content of the textarea. The attribute of the tag can be passed as a hash function as an argument.

6.37.2. HTML generation method #

You can use the corresponding HTML tag signature in the CGI instance to create the HTML tag, as shown below:

Example #

#!/usr/bin/rubyrequire"cgi"cgi=CGI.new("html4")cgi.out{cgi.html{cgi.head{"\\n"+cgi.title{"This
Is a Test"} } +cgi.body{"\\n"+cgi.form{"\\n"+cgi.hr+cgi.h1{"A Form:"}
+"\\n"+cgi.textarea("get_text")+"\\n"+cgi.br+cgi.submit} } } }

6.37.3. CGI object Properties #

You can use the following properties in the CGI instance:

Attribute

Return value

Accept

Acceptable MIME types

accept_charset

Acceptable character set

accept_encoding

Acceptable coding

accept_language

Acceptable language

auth_type

Acceptable type

raw_cookie

Cookie data (original string)

content_length

Content length

content_type

Content type

From

Client e-mail address

gateway_interface

CGI version

path_info

Path

path_translated

Converted path

Query_string

Query string

referer

Visit the web site before

remote_addr

Client host address (IP)

remote_host

Client hostname

remote_ident

Client name

remote_user

Authenticated user

request_method

Request method (GET, POST, etc.)

script_name

Parameter name

server_name

Server name

server_port

Server port

server_protocol

Server protocol

server_software

Server software

user_agent

User agent

Principles, Technologies, and Methods of Geographic Information Systems  102

In recent years, Geographic Information Systems (GIS) have undergone rapid development in both theoretical and practical dimensions. GIS has been widely applied for modeling and decision-making support across various fields such as urban management, regional planning, and environmental remediation, establishing geographic information as a vital component of the information era. The introduction of the “Digital Earth” concept has further accelerated the advancement of GIS, which serves as its technical foundation. Concurrently, scholars have been dedicated to theoretical research in areas like spatial cognition, spatial data uncertainty, and the formalization of spatial relationships. This reflects the dual nature of GIS as both an applied technology and an academic discipline, with the two aspects forming a mutually reinforcing cycle of progress.

Powered by Django & PostgreSQL (with PostGIS)