This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line!
See this thread for details.
The moose likes Struts and the fly likes Struts and Chineese characters Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts and Chineese characters " Watch "Struts and Chineese characters " New topic

Struts and Chineese characters

syd kahn

Joined: Aug 23, 2005
Posts: 12
I have a text field on a Struts form that i type 展中国家或经济处于 into.

i send it out to as a mail message by appending the string variable to the output - the email gets garbled characters.

I put the string variable into a database using a CallableStatement and setString - it gets to the DB garbled. I know the datbaase can handle it (SQL SERVER 2000) since that is where i copied the characters from in the first place.

I am reading about getbytes() but am unsure of the usage or how to get the variable (which it says java deals with as utf-8) out to the databse/e-mail in the proper form

in short - i'm stuck
Wagner Danda Da Silva Filho
Ranch Hand

Joined: Mar 21, 2003
Posts: 80
Once I got problems with encoding in Struts, then I solve it after changing the page directive to the correct encoding. E.g.:

<%@ page language="java" pageEncoding="UTF-8"%>

syd kahn

Joined: Aug 23, 2005
Posts: 12
I found the answer to my problem here

By the time you get a chance to deal with the variables Struts has already parsed the response(request?) stream - and mangled the characters. this is the source for a filter that forces UTF-8 before the struts framework gets it grimy little hands on it.

The database insert now works - and the display page is good - just need to figure out how to get the charactes into the e-mail....

Thank G.D for GOOGLE....
syd kahn

Joined: Aug 23, 2005
Posts: 12
Now that I have the web pages and the database displayng the characters correctly - the email is now broken - it only shows ??? for the data - I am using the jakarta commons (included in netbeans) and sending html mail. Is htere a way to tell it to accept UTF-8.

I can see the varaible's content in the IDE as \23edr\1111\222 etc - but they are not finding their way into the email correctly.

Any Ideas

[ November 18, 2005: Message edited by: syd kahn ]
[ November 18, 2005: Message edited by: syd kahn ]
Nathan Pruett

Joined: Oct 18, 2000
Posts: 4121

Moving to the Struts forum, since this seems to be a struts problem...

Write once, run anywhere, because there's nowhere to hide! - /. A.C.
syd kahn

Joined: Aug 23, 2005
Posts: 12
For those that have this problem - i was using the org.apache.commons.mail set of classes to send the mail. This is a wrapper around the javax.mail classes from sun

all that i had to do was add the setCharset line to get it all working...

wood burning stoves
subject: Struts and Chineese characters
It's not a secret anymore!