How to check the charset of string in Java?

后端 未结 5 1720
梦谈多话
梦谈多话 2020-12-07 00:29

In my application I\'m getting the user info from LDAP and sometimes the full username comes in a wrong charset. For example:

ТеÑÑ61 ТеÑÑовиÑ61
         


        
5条回答
  •  一整个雨季
    2020-12-07 01:07

    In your web-application, you may declare an encoding-filter that makes sure you receive data in the right encoding.

    
        Explicitly set the encoding of the page to UTF-8
        encodingFilter
        org.springframework.web.filter.CharacterEncodingFilter
        
            encoding
            UTF-8
        
        
            forceEncoding
            true
        
    
    

    A spring provided filter makes sure that the controllers/servlets receive parameters in UTF-8.

提交回复
热议问题