0

Having a dispachetServlet configured as:

@Override
protected Filter[] getServletFilters()
{
    return new Filter[] { new HiddenHttpMethodFilter(), characterEncodingFilter() };
}

private static final String CHARACTER_ENCODING = "UTF-8";

private CharacterEncodingFilter characterEncodingFilter()
{
    final CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter();
    characterEncodingFilter.setEncoding( CHARACTER_ENCODING );
    characterEncodingFilter.setForceEncoding( true );
    return characterEncodingFilter;
}

And a meta on html as:

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

Why when I submit a form with text characters: ç, ñ... I'm getting on controller wrong characters like: çaça

How can I fix it?

UPDATED

I'm using thymeleaf instead of jsp and I'm getting parameters:

@RequestMapping( value = REGISTRATION, method = POST )
public String processRegistration( @ModelAttribute("userForm") User user, Model model )
{
    if( userService.existEmail(user)  )
    {
        model.addAttribute("duplicatedMail", true);
        return REGISTRATION_VIEW;
    }
    if( userService.existUsername(user)  )
    {
        model.addAttribute("duplicatedUsername", true);
        return REGISTRATION_VIEW;
    }
    userService.register( user );
    return REGISTRATION_SUCCESS_VIEW;
}
2
  • Do you use JSP? If so, do you have something like <%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> in the JSP? Commented Jul 6, 2014 at 2:13
  • Do you submit a GET or a POST? How do you get the parameters? Commented Jul 6, 2014 at 3:19

1 Answer 1

1

Try following:

return new Filter[] { characterEncodingFilter(), new HiddenHttpMethodFilter() };

Note: You need to add CharacterEncodingFilter before HiddenHttpMethodFilter since latter calls ServletRequest.getParameter method internally.

Hope this helps.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.