servlet HttpServletRequest class 3 Chinese character encoding issues

  

method one:

// Get request parameters 
String = req.getParameter username ( "username" );
 // . 1 prior to encoding iso8859-1
 @ 2 and then to decode utf-8 
username = new new String (username.getBytes ( "ISO-8859 -1 ")," UTF-8 ");

 

Method Two:

// set the character set of the request body is UTF-8, thereby solving the problem of post distortion Chinese request 
req.setCharacterEncoding ( "UTF-. 8" );
System.out.println ( "------------- the doPost -----------------------" );
 // Get request parameters 
String username = req.getParameter ( "username " );
String password = req.getParameter("password");
String[] hobby = req.getParameterValues("hobby");
System.out.println ( "User Name:" + username);
System.out.println("密码:" + password);
System.out.println ( "Interests:" + Arrays.asList (hobby)) ;

 

Guess you like

Origin www.cnblogs.com/superxuezhazha/p/12585804.html