如何接收非英文字符作为 spring bean

how to receive nonenglish character as spring bean

在我的项目中,我从 form.If 获取非英语字符 a 获取表单参数作为 @RequestParam.It 显示非英语 character.If 我获取表单参数作为 bean 它显示一些不需要的字符。

<form action="selva" method="get">
<input type="text" name="s" value="அன்பு" />
<input type="submit" value="fgf"/>
</form>
It displays:அன்பு
<form:form method="post" enctype="multipart/form-data" accept-charset="UTF-8" action="multipleSave" modelAttribute="multipleSave">
    <input type="text" name="userName" value="அன்பு"/>
<input type="submit" value="submit"> 
</form:form>
It prints : திலà®à®µà®¤à®¿

如何解决这个错误。

任何帮助将不胜感激!!!

您可能错过了 org.springframework.web.filter.CharacterEncodingFilter。您可以通过 web.xml

添加它
<filter>
    <filter-name>encodingFilter</filter-name>
    <filter-class>org.springframework.web.filter.CharacterEncodingFilter </filter-class>
    <init-param>
        <param-name>encoding</param-name>
        <param-value>UTF-8</param-value>
    </init-param>
</filter>

<filter-mapping>
    <filter-name>encodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

或通过Spring java配置文件:

import org.springframework.web.filter.CharacterEncodingFilter;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;

import javax.servlet.FilterRegistration;
import javax.servlet.ServletContext;

public class WebAppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
    @Override
    public void onStartup(ServletContext servletContext) throws ServletException {
        super.onStartup(servletContext);
        ....
        CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter();
        characterEncodingFilter.setEncoding("UTF-8");
        characterEncodingFilter.setForceEncoding(true);
        FilterRegistration.Dynamic filter = servletContext.addFilter("characterEncodingFilter", characterEncodingFilter);
        filter.addMappingForUrlPatterns(null, false, "/*");
        .....
    }
}