In my project i am getting the nonenglish character from form.If a get a form parameters as @RequestParam.It display the nonenglish character.If i get the form parameter as bean it displays some unwanted character.
<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 : திலà®à®µà®¤à®¿
How to resolve this error.
Any help will be greatly appreciated!!!
You are probably missing org.springframework.web.filter.CharacterEncodingFilter
. You can add it either via 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>
or via Spring java configuration file:
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, "/*");
.....
}
}