Naor
Naor

Reputation: 24053

spring mvc charset

I am using spring mvc. I am writing in Hebrew so in my jsp form I ask the user to give his name in Hebrew. Here is the form:

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<form:form method="post" action="registration-submit.html">
    אנא מלא את הפרטים הבאים בכדי להשלים את הרשמתך:
    <table>
        <tr>
            <td>שם:</td>
            <td><form:input path="name" type="text" id="nameInput"/></td>
        </tr>
        <tr>
            <td>סיסמא:</td>
            <td><form:input path="password" type="password" id="passwordInput"/></td>
        </tr>
        <tr>
            <td>וידוא סיסמא:</td>
            <td><input type="password" id="passwordVerifyInput"/></td>
        </tr>
        <tr>
            <td>דואר אלקטרוני:</td>
            <td><form:input path="email" type="text" id="emailInput"/></td>
        </tr>
        <tr>
            <td colspan="2">
                <input type="submit" value="הירשם"/>
            </td>
        </tr>
    </table>
</form:form>

For registration-submit.html I have the controller:

@RequestMapping(value = "/registration-submit", method = RequestMethod.POST)
    public ModelAndView showRegistrationSubmitPage(
            @ModelAttribute("registrationForm") final RegistrationForm registrationForm,
            BindingResult result) {
                ...
                ...
}

When I add registrationForm.name to the watch, I see: × ××ר (unreadable characters) instead of the Hebrew name.
The jsp file is saved with UTF-8 charset. Why do I get unreadable characters from the form? How can I set the charset of spring?

Upvotes: 0

Views: 571

Answers (2)

Sajan Chandran
Sajan Chandran

Reputation: 11487

You need to do something like this

 <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> 

 <init-param> 

    <param-name>forceEncoding</param-name> 

    <param-value>true</param-value> 

 </init-param> 

 <filter-name>encodingFilter</filter-name> 

<url-pattern>/*</url-pattern> 

Upvotes: 2

Bozho
Bozho

Reputation: 597006

Try registering a CharacterEncodingFilter in web.xml

Upvotes: 2

Related Questions