I. Basic jsp and serlvet Chinese garbled solutions
(The complete solution notes are provided before, and you will not be able to post them if you are free of time)
II. apache commons-fileupload was used as the upload component in October 2011. Garbled code was used to resolve the error when submitting a form field containing fields and files:
1. Same as "1.", use a filter to encode all request requests with UTF-8
2. Solve the garbled characters of form field values:
The code is as follows: |
Copy code |
If (item. isFormField ()){ // If item is a normal form field String name = item. getFieldName (); String value = item. getString ("UTF-8"); // solves garbled characters in the values of form fields }
|
3. Solve the garbled path of the uploaded file:
The code is as follows: |
Copy code |
FileItemFactory factory = new DiskFileItemFactory (); ServletFileUpload upload = new ServletFileUpload (factory ); Upload. setHeaderEncoding ("UTF-8"); // solves the path garbled setting of the uploaded file |