aolesins
Mar 21st, 2006, 12:18 PM
Hi all!
I know that this problem is world's-old, but I dont know how to solve it.:)
I'm writing simple MVC application which uses Jsp as views.
I'm using simple form validator, which rejects empty fields with apropriate message. Problem is, that my message is in iso-8859-2 encoding, so some characters aren't encoded properly (it looks like "backing spring logic" is using ISO-8859-1 - some kind of default). I looked through some spring.java files in order to change this default behavior, but i havent found a solution.
(my pages are all in ISO-8859-2 encoding, as well as jsp files)
When I post this post-validator messages, im using this construct:
<spring:bind path="ruleCommand.business_code">
<td >
<input name="business_code" size="20" class="text" value="<c: out value="${status.value}"/>"></input></td>
<td >
<font color="red"><c: out value="${status.errorMessage}"/></font> <!-- here it prints bad characters -->
</td></spring:bind>
I had the same problem with spring:bind tag in general, but when i started using charcterEncdoing filter for HttpServletRequest it worked.
Regards,
Artur
SOLUTION:
I came up to the solution, and it wasnt Spring at all
Java internally stores Strings as UTF-8. When I explicitily converted my Strings to iso-8859-2 it worked:
private static final byte[] valid_from_err = "some iso-8859-2 specific text"
.getBytes();
protected Map referenceData(HttpServletRequest request, Object command,
Errors errors, int page) throws Exception {
Map rules = new HashMap();
rules.put("text",new String(valid_from_err,"ISO-8859-2");
....
}
when in my jsp i use <c: out value="${text}" it's ok.
I wonder if there is simpler solution, other than using UTF-8:)
Thanks for patience,
Artur
I know that this problem is world's-old, but I dont know how to solve it.:)
I'm writing simple MVC application which uses Jsp as views.
I'm using simple form validator, which rejects empty fields with apropriate message. Problem is, that my message is in iso-8859-2 encoding, so some characters aren't encoded properly (it looks like "backing spring logic" is using ISO-8859-1 - some kind of default). I looked through some spring.java files in order to change this default behavior, but i havent found a solution.
(my pages are all in ISO-8859-2 encoding, as well as jsp files)
When I post this post-validator messages, im using this construct:
<spring:bind path="ruleCommand.business_code">
<td >
<input name="business_code" size="20" class="text" value="<c: out value="${status.value}"/>"></input></td>
<td >
<font color="red"><c: out value="${status.errorMessage}"/></font> <!-- here it prints bad characters -->
</td></spring:bind>
I had the same problem with spring:bind tag in general, but when i started using charcterEncdoing filter for HttpServletRequest it worked.
Regards,
Artur
SOLUTION:
I came up to the solution, and it wasnt Spring at all
Java internally stores Strings as UTF-8. When I explicitily converted my Strings to iso-8859-2 it worked:
private static final byte[] valid_from_err = "some iso-8859-2 specific text"
.getBytes();
protected Map referenceData(HttpServletRequest request, Object command,
Errors errors, int page) throws Exception {
Map rules = new HashMap();
rules.put("text",new String(valid_from_err,"ISO-8859-2");
....
}
when in my jsp i use <c: out value="${text}" it's ok.
I wonder if there is simpler solution, other than using UTF-8:)
Thanks for patience,
Artur