File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Problem with encoding using Tiles Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Problem with encoding using Tiles" Watch "Problem with encoding using Tiles" New topic
Author

Problem with encoding using Tiles

Alice Wong
Greenhorn

Joined: Oct 12, 2004
Posts: 22
I'm using Tiles to define my page:
<definition name=".userList" extends=".mainLayout">
<put name="browser-title" value="Hello" />
<put name="body-content" value="/hello.jsp" />
</definition>

in hello.jsp and mainLayout.jsp, I have put the line
<%@ page pageEncoding="UTF-8" contentType="text/html;charset=UTF-8" language="java" %>

however, when I load the page, the encoding is Western European. Have I missed out any settings that may affect the encoding? Thanks!
Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982
I have faced with this issue before. I use a *strange* way to fix it, but I am not sure whether it works for you.

I have set the encoding and charset as UTF-8 in the mainLayout.jsp, however, I havent set any encoding and charset for the *included* JSPs.

You might try whether this work.

Nick


SCJP 1.2, OCP 9i DBA, SCWCD 1.3, SCJP 1.4 (SAI), SCJD 1.4, SCWCD 1.4 (Beta), ICED (IBM 287, IBM 484, IBM 486), SCMAD 1.0 (Beta), SCBCD 1.3, ICSD (IBM 288), ICDBA (IBM 700, IBM 701), SCDJWS, ICSD (IBM 348), OCP 10g DBA (Beta), SCJP 5.0 (Beta), SCJA 1.0 (Beta), MCP(70-270), SCBCD 5.0 (Beta), SCJP 6.0, SCEA for JEE5 (in progress)
Alice Wong
Greenhorn

Joined: Oct 12, 2004
Posts: 22
Thanks Nick. Unfortunately that doesn't work for me.
I'm now using Tomcat 5.0 and have set a filter for character encoding in my web.xml in my application:

<filter>
<filter-name>Set Character Encoding</filter-name>
<filter-class>com.web.common.filter.SetCharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>Set Character Encoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

The filter class is simply downloaded from Apache.
Any idea on why the encoding is not correct? Thanks!
Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982
How about setting the charset for request by


together with my previous recommendation?

You might also read the "UTF-8" string from web.xml as well.

Nick
Alice Wong
Greenhorn

Joined: Oct 12, 2004
Posts: 22
request.setCharacterEncoding("UTF-8"); <- this has already been put inside the filter class
Alice Wong
Greenhorn

Joined: Oct 12, 2004
Posts: 22
I test the other way round....If i explicitly load hello.jsp (with the code for fetching properties from Form Bean removed), the encoding is UTF-8.
I'm wondering whether the encoding of my Form Bean is not correct. I'm now using Eclipse to edit and build my application. Should I explicitly set the encoding in Eclipse?
Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982
Should I explicitly set the encoding in Eclipse?

The encoding in the editor should not really affect the application server. However, have you tried this way and it works?

Nick
Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982
request.setCharacterEncoding("UTF-8"); <- this has already been put inside the filter class

So, what is the charset of the request inside the action, not the filter? Is it still UTF-8, or it has been changed back to ISO-8859-1?

Nick
Alice Wong
Greenhorn

Joined: Oct 12, 2004
Posts: 22
Nick,

No...I'm just thinking of trying to build the project with UTF-8 as encoding. Do you know where can I set that in Eclipse?
Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982
I am not sure whether we can set the encoding of the IDE, however, I guess Lasse might know. So, might be we wait for his response. Sorry for that.

Nick
Alice Wong
Greenhorn

Joined: Oct 12, 2004
Posts: 22
Nevermind! =) Thanks for your help!
Alice Wong
Greenhorn

Joined: Oct 12, 2004
Posts: 22
Nick, just wanna tell you that I've solved the problem simply by re-installing the Tomcat! Sounds amazing, right?
Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982
I've solved the problem simply by re-installing the Tomcat! Sounds amazing, right?


Seems that problems could be resolved by re-start or re-installation.

Anyway, problem solved is great!

Nick
Wiz Cheng
Greenhorn

Joined: Mar 11, 2005
Posts: 1
Hi ~

I have suffer the problem with the same configuration.
Please see if you have your filter ("Set Character Encoding") configured as the first one!

Since after the first "request.getParameter()" is called, "request.setCharacterEncoding()" (inside "Set Character Encoding" filter) will not function.

As all following "request.getParameter()" call will use the same encoding it used in the first call !!

see if help ^ ^
good luck !
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with encoding using Tiles