Extracting Input Parameters


When a client machine sends an HTTP command to the server, it also provides the input arguments required to run the application. The most common HTTP commands used with web-based applications are GET and POST . With the GET command, the input arguments are concatenated into a single string called the query string that is passed to the server. This method is appropriate for applications that don't require a large number of input arguments. When the POST command is used, the arguments are included in an HTML form that accompanies the POST command.

In either case, the input parameter data will consist of a series of name-value pairs. The "name" is the name of the input parameter as it is defined in the HTML form on the client web browser. The "value" is the value of the input parameter expressed as a string. The getParameter() method from the ServletRequest interface can be used to return the value associated with a given parameter name. Here is the syntax of this method.

 public String getParameter(String name) 

For example, if the HTML form on the client machine defined input parameters named "units" and "altitude" the servlet could extract the values associated with the input parameters using the following syntax ”

 String units = request.getParameter("units"); String altitude = request.getParameter("altitude"); 

The request variable is a reference to the HttpServletRequest object passed to the doGet() or doPost() method. The value associated with the "altitude" parameter is returned as a String . It would then be converted into a floating point value before it was used as an input value for the application.



Technical Java. Applications for Science and Engineering
Technical Java: Applications for Science and Engineering
ISBN: 0131018159
EAN: 2147483647
Year: 2003
Pages: 281
Authors: Grant Palmer

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net