JSP basic Syntax (v)

Source: Internet
Author: User

: 1. Solve Chinese garbled problem

<%@ page language= "java" pageencoding= "GBK"%>

JSP page text box input with Chinese information, at this time to get input content, found that the Chinese display is not correct, garbled;

processing : Add the following code to the corresponding JSP page

<body>
<%
Request. setcharacterencoding ("GBK");// Set uniform encoding
String str = request.getparameter ("info");//Receive form submission parameters
%>
Output information
</body>

2. Receive Request parameters

getparameter (): Uses such as text box, radio button (radio), Password box (password), hidden field (hidden), etc., because the parameter names of these controls are generally only one and are not duplicated;

getparametervalues (): If a check box (checkbox), the name of the parameter repeats, is a set of array form, if the use of GetParameter () received, will only receive the first selected value;

When you use both to receive a parameter value, it is possible to have a null value, in the use of whether or not to be empty judgment, or else there may be nullpointerexception exception!

For example: check box

String str[] = Request. getparametervalues ("inst");

if (str! = null) {

for (int i = 0; i < str.length; i++) {

<%=str[i]%>

}

}

the source of the parameter : First, come to the form submitted;

The second is the way of address rewriting brought over:

Example: https://localhost:8080/xx/aaa.do?name=mxz&password=123

Get Commit: The submitted content will appear after the address bar; https://localhost:8080/xx/aaa.do?name=mxz&password=123

Post submission: The submitted content is not displayed in the address bar; Https://localhost:8080/xx/aaa.do?

Getparameternames (): Returns the name of all request parameters, returns the value type Enumration, then uses the hasmoreelements () method to determine if there is content, and uses the nextelement () method to remove the content;

check box:* * The main purpose is to distinguish the different parameters of the receiving operation;

Once all the parameter names are obtained by Getparameternames , then the corresponding contents must be getparameter () or getparametervalues (). all that begin with a ** are received in an array form.

3. Show All header information

request.getheadernames (): Gets the name of the header information; Request.getheader (): Gets the contents of each header information;

4. When the server wants to obtain information about the client, it can use the request built-in object to obtain information, such as:

String method = Request.getmethod (); Get the submission method

String IP = request.getremoteaddr ();//Get the IP address of the customer

String path = Request.getservletpath ();//Get access Path

String Contextopath = Request.getcontextpath ();//Get Application Context

JSP basic Syntax (v)

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.