0

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?

2 Answers 2

2

Try registering a CharacterEncodingFilter in web.xml

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

1 Comment

And make sure it's the first filter activated
2

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> 

1 Comment

make sure it's the first filter

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.