Analysis on CGI supported by jsp http Server

Source: Internet
Author: User

Jsp http server supports CGI. In short, it supports the client to call the CGI routine of the server. On the server side, CGI is generally stored as executable files, such as executable files and executable scripts ). These CGI execution files can be run independently or the client requests can be run as parameters. The HTTP server needs to call the CGI executable file, pass the Request Parameters of the client to the CGI program, and feedback the CGI execution result to the client.

1. Call of CGI programs that do not require parameters on the jsp http Server

For CGI programs that do not require parameters, the function module has been fixed to the CGI program. When called, you can execute this function module. This type of CGI program is generally used in scenarios with relatively fixed functions. The following code supports both CGI that requires parameters and CGI that does not require parameters:

 
 
  1. //Parameter is null   
  2. if(params.equals("") == true) {   
  3. command = fileName;   
  4. }   
  5. else //Generate the command line {   
  6. command = fileName + " " + params;   
  7. }   
  8. //Execute CGI process as child process Process proc = m_rt.exec(command, null);   
  9. //Create CGI process output stream   
  10. BufferedReader pin = new BufferedReader(new InputStreamReader(proc.getInputStream() ) );   
  11. String line = null;   
  12. //Get the output from CGI process   
  13. while( (line = pin.readLine() ) != null) {   
  14. m_sout.println(line);   
  15. }  
  16. //Wait for CGI process finish   
  17. proc.waitFor(); 


In the above Code, the CGI executable file is called through the exec interface of the Java Runtime class, And the CGI execution output is returned to the client.

2. Call of CGI programs whose parameters are required by the jsp http Server

For CGI programs that require parameters, the function modules are not fixed. Instead, you need to input parameters to execute the corresponding functions. This type of CGI program is relatively flexible. When called, the HTTP server must pass the parameter lines in the client request into the CGI process, parse the request in the CGI program, and then execute the corresponding module. The communication between the HTTP server and CGI process can be implemented in three ways:

1) input the execution parameters in command line mode. See the above Code "command = fileName +" "+ params. Use the executable files and parameters as command lines to pass in the call.
2) written to the standard input stdin of the CGI process. The CGI program only needs to read the corresponding parameter lines from the standard input.
3) write the parameter lines to the environment variable QUERY_STRING of the CGI process. CGI reads the command line parameters from the environment variable QUERY_STRING.

  1. Get database connection in JSP
  2. Introduction to JSP Action
  3. Simplified code in JSP expressions
  4. Detailed explanation of JSP-to-Servlet Conversion
  5. Introduction to JSP Elements

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.