Solution to the problem of obtaining form data and garbled code in Java Web
First, use a user submission interface as an example (text box, password box, selection, drop-down form, etc.), and the effect is as follows
Note: the definition and usage of the action attribute of HTML < form > tag are:
The property value is URL, indicating where to send form data. Possible values:
Absolute URL - points to other sites (such as SRC = "www.example. COM / example. HTM")
Relative URL - points to a file within the site (such as SRC = "example. HTM")
For example, the following form has two input fields and a submit button. When the form is submitted, the form data will be submitted to the page named "form_action. ASP":
The method is get, so the information is obtained in the doget method of the servlet
Reason for request parameter garbled
URL encoding is a format that browsers use to package form input. The browser obtains all names and values from the form, encodes them with name / value parameters (removes those characters that cannot be transmitted, ranks the data, etc.) as part of the URL or sends them to the server separately.
Different request methods correspond to different solutions:
post ―- request. SetCharacterEncoding ("client encoding set");
Get garbled code manual solution
Simplify the above writing: username = new string (username. GetBytes ("iso-8859-1"), "UTF-8");
Get garbled code configuration Tomcat default decoding character set
In Tomcat / conf / server xml
Add a property uriencoding = "UTF-8" in connector
Conclusion: during development, try not to modify the default decoding set of Tomcat. When submitting a request, try to use post. If you have to use get, code manually