You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Zsolt Koppany <zk...@intland.com> on 2003/12/26 11:44:48 UTC

What is wrong with this upload filename (UTF-8) decoding?

Hi,

my application has to support UTF-8 including when files are uploaded with
UTF-8 characters in the filename (for example: ??????????????.txt).

I use a servlet filter that always call
request.setCharacterEncoding("UTF-8") and my jsp pages contain
response.setContentType("text/html; charset=UTF-8");

Everything works fine except that I have problems with decoding of the name
of uploaded filenames.

I use the code below to get the name of the uploaded filename:

String nm = formFile.getFileName();
String filename = new String(nm.getBytes(), "UTF-8");

The code above converts only the first couple of characters correctly
(result: ??????????????????????.txt).

Any ideas how to fix the problem?

I use TC-4.1.29, Struts-1.1, jdk1.4.2_02 Windows-XP.

Zsolt



---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


How test for attribute?

Posted by e-denton Java Programmer <ja...@e-denton.com>.
Hi,

I am trying to test for the presence of a request attribute called "PCAT".

This works:

if (request.getAttribute ("PCAT") != null)

This doesn't work:

<logic:present parameter="PCAT">
</logic:present>

What Struts logic tag would work?

 Thanks, 

Will

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: What is wrong with this upload filename (UTF-8) decoding?

Posted by Jason Lea <ja...@kumachan.net.nz>.
I have not used the file upload yet, but I believe you need to set the 
encoding for the headers

formFile.setHeaderEncoding("UTF-8")

setHeaderEncoding does this:
"Specifies the character encoding to be used when reading the headers of 
individual parts. When not specified, or |null|, the platform default 
encoding is used."
If this was running on a English operating system it is probably 
defaulting to the Latin-1 encoding.

 From this Java Doc:
http://jakarta.apache.org/commons/fileupload/apidocs/org/apache/commons/fileupload/FileUploadBase.html#setHeaderEncoding(java.lang.String)

Please post back to the forum if this works.  I would be interested in 
the result.

Zsolt Koppany wrote:

>Hi,
>
>my application has to support UTF-8 including when files are uploaded with
>UTF-8 characters in the filename (for example: ??????????????.txt).
>
>I use a servlet filter that always call
>request.setCharacterEncoding("UTF-8") and my jsp pages contain
>response.setContentType("text/html; charset=UTF-8");
>
>Everything works fine except that I have problems with decoding of the name
>of uploaded filenames.
>
>I use the code below to get the name of the uploaded filename:
>
>String nm = formFile.getFileName();
>String filename = new String(nm.getBytes(), "UTF-8");
>
>The code above converts only the first couple of characters correctly
>(result: ??????????????????????.txt).
>
>Any ideas how to fix the problem?
>
>I use TC-4.1.29, Struts-1.1, jdk1.4.2_02 Windows-XP.
>
>Zsolt
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>
>  
>

-- 
Jason Lea



---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: What is wrong with this upload filename (UTF-8) decoding?

Posted by Firat TIRYAKI <fi...@pleksus.com.tr>.
I think it depends on the operating system on your machine where the app
server is running... Try to solve the problem with your OS.

F.

----- Original Message ----- 
From: "Zsolt Koppany" <zk...@intland.com>
To: "Struts Users Mailing List" <st...@jakarta.apache.org>
Sent: Friday, December 26, 2003 12:51 PM
Subject: RE: What is wrong with this upload filename (UTF-8) decoding?


> After posting now I see that the posted email contains "?" characters
> instead of the original chinese characters I used in my example.
>
> Zsolt
>
> > -----Original Message-----
> > From: Zsolt Koppany [mailto:zkoppanylist@intland.com]
> > Sent: Friday, December 26, 2003 11:45 AM
> > To: Struts Users Mailing List
> > Subject: What is wrong with this upload filename (UTF-8) decoding?
> >
> >
> > Hi,
> >
> > my application has to support UTF-8 including when files are uploaded
with
> > UTF-8 characters in the filename (for example: ??????????????.txt).
> >
> > I use a servlet filter that always call
> > request.setCharacterEncoding("UTF-8") and my jsp pages contain
> > response.setContentType("text/html; charset=UTF-8");
> >
> > Everything works fine except that I have problems with decoding
> > of the name
> > of uploaded filenames.
> >
> > I use the code below to get the name of the uploaded filename:
> >
> > String nm = formFile.getFileName();
> > String filename = new String(nm.getBytes(), "UTF-8");
> >
> > The code above converts only the first couple of characters correctly
> > (result: ??????????????????????.txt).
> >
> > Any ideas how to fix the problem?
> >
> > I use TC-4.1.29, Struts-1.1, jdk1.4.2_02 Windows-XP.
> >
> > Zsolt
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: struts-user-help@jakarta.apache.org
> >
> >
> >
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


RE: What is wrong with this upload filename (UTF-8) decoding?

Posted by Zsolt Koppany <zk...@intland.com>.
After posting now I see that the posted email contains "?" characters
instead of the original chinese characters I used in my example.

Zsolt

> -----Original Message-----
> From: Zsolt Koppany [mailto:zkoppanylist@intland.com]
> Sent: Friday, December 26, 2003 11:45 AM
> To: Struts Users Mailing List
> Subject: What is wrong with this upload filename (UTF-8) decoding?
>
>
> Hi,
>
> my application has to support UTF-8 including when files are uploaded with
> UTF-8 characters in the filename (for example: ??????????????.txt).
>
> I use a servlet filter that always call
> request.setCharacterEncoding("UTF-8") and my jsp pages contain
> response.setContentType("text/html; charset=UTF-8");
>
> Everything works fine except that I have problems with decoding
> of the name
> of uploaded filenames.
>
> I use the code below to get the name of the uploaded filename:
>
> String nm = formFile.getFileName();
> String filename = new String(nm.getBytes(), "UTF-8");
>
> The code above converts only the first couple of characters correctly
> (result: ??????????????????????.txt).
>
> Any ideas how to fix the problem?
>
> I use TC-4.1.29, Struts-1.1, jdk1.4.2_02 Windows-XP.
>
> Zsolt
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org