views:

489

answers:

2

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

+3  A: 

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.

kgiannakakis
At least in tomcat 5
Maurice Perry
Aheum... it's setCharacterEncoding actually
Maurice Perry
You are right. I've corrected it.
kgiannakakis
A: 

I am working in i18n requirement. In my application, the user is going to enter data also in all languages.

Let say the user entered "सतीश कुमार" and it got stored in database as "ப௠ர௠பர௠ப". But next time when the user want to see the same data in to the user interface, it is showing the same.

I changed the folliwing things in my jsp page and the result is like this.

  1. I set the content type of jsp as

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

Now the property files(resource boundle) is working fine(I put \uxxx format in property file). But the database stuffs did not worked. It is showing as it is in database.

  1. I set the meta type in head tag as

META http-equiv="Content-Type" content="text/html; charset=UTF-8"

Now the database data was coming properly, but the resource boundle did not worked.. The resource boundle is showing some other junk stuffs.

Can anybody suggest me some way where both the stuffs will work. I checked the database is supporting UTF-8.

Satish
Welcome at Stackoverflow! You've posted an answer. But it actually contains a question. Please use the `Ask Question` button at the top right to post a question. Feel free to include links to topics you found, but didn't help in answering the question.
BalusC