如何接收非英语字符作为春豆

时间:2015-07-21 11:33:08

标签: java html spring tamil

在我的项目中,我从form中获取非英语字符。如果得到一个表单参数为@ RequestParam.It显示非英语字符。如果我将表单参数作为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 : திலà®à®µà®¤à®¿

如何解决此错误。

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

1 个答案:

答案 0 :(得分:1)

您可能遗失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, "/*");
        .....
    }
}