wokena
wokena

Reputation: 1359

Please help with my JSP Internationalization problem

I have problem with I18N in JSP, specifically, with forms.

When I enter some Czech characters (e.g., "ěščřžýá...") into my page one form, into the field "fieldOne", and then show text from that field on page two, instead of Czech characters I see this as "ÄÄ". (Note, the second page gets the Czech characters with "request.getProperty("fieldOne")")

Here is the source code:

Page one:

<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>

<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic" %>

<html>
 <head></head>
 <body>
    <form action="druha.jsp" method="post">
       <input type="textarea" name="fieldOne">
       <input type="submit">
    </form>
 </body>
</html>

Page two:

<%@page contentType="text/html" pageEncoding="UTF-8"%>

<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic" %>

<html>
 <head></head>
 <body>
    <h1>The text: </h1> <%=request.getProperty("fieldOne")%>
 </body>
</html>

Thanks for help...

Upvotes: 3

Views: 990

Answers (1)

kgiannakakis
kgiannakakis

Reputation: 104178

Which container are you using? This information is important for this kind of problems.

Anyway, try calling

request.setCharacterEncoding("UTF-8");

before reading the parameter. Sometimes setting the page encoding in the header directive isn't enough. You definitely need to do this in Tomcat and servlets, I assume that this could be also the case for JSPs.

Upvotes: 4

Related Questions