Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with encoding using Tiles

 
Alice Wong
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Alice Wong
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
request.setCharacterEncoding("UTF-8"); <- this has already been put inside the filter class
 
Alice Wong
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nevermind! =) Thanks for your help!
 
Alice Wong
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nick, just wanna tell you that I've solved the problem simply by re-installing the Tomcat! Sounds amazing, right?
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 !
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic