You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Kapil Sharma <ka...@iap-online.com> on 2007/05/08 07:58:16 UTC

FileName characters.

Hii 

I am using struts, jboss 4.0.1 and downloading file from the JSP as an
atachment.. 

My file has japanese and chinese characters...

The problem is that when i m directly opening this file on the fly from the
Dialog box by clicking on the open button, it is showing me some characters
like %3s or something like. 

These characters are appearing file on the dialog box and also saving the
file is OK but i don't know why they get something like while opening on the
fly

I hope these charcters are not properly decode.

I used

try {

fileName = new String(fileName.getBytes("ISO-8859-1"), "UTF-8");
fileName = URLEncoder.encode(fileName, "UTF-8");
fileName = fileName.replace('+', ' ');

} catch (UnsupportedEncodingException UEEx) {
}

URLEncoder.encode(filename,"UTF-8") for non Ascii characters. FileName in
the popup box is coming all right and click on the save button is correctly
saving the file with name.

I am also using 

response.setCharacterEncoding("UTF-8");
response.addHeader("Content-Transfer-Encoding", "UTF-8");
response.setHeader("Content-Transfer-Encoding", "UTF-8");
response.setHeader("Content-Disposition", "attachment; filename=\"" +
fileName+ "\"");

Is it related with struts or encoding problem associated with the
environment

Pls help me.. 


Thanks and Regards,
Kapil Sharma 



RE: FileName characters.

Posted by Kapil Sharma <ka...@iap-online.com>.
>>I see, but does the program that you use to open the file work correctly?
If
yes I suppose you don't have to worry :-)


Yes the file is opening correctly . But saving this opened file as it is
will again show the  %xx characters .

BTW user has to enter its own name to the file.

Problem lies beacause in jsp The thing appears as

Filename                               Download

 japaneseCharacters1             link1
 japaneseCharacters2	         link2


and it does not appear correctly while saving (opening first).



Anyway thanks for all your answers.



Thanks and Regards,
Kapil Sharma



-----Original Message-----
From: Antonio Petrelli [mailto:antonio.petrelli@gmail.com]
Sent: Tuesday, May 08, 2007 5:43 PM
To: Struts Users Mailing List
Subject: Re: FileName characters.


2007/5/8, Kapil Sharma <ka...@iap-online.com>:
>
> 2.
>
> The attachment dialog box shows correct filename.
> Also saving the file to my local disk also is correct
>
> But when i try to open the file directly on clik of "open" button from
> dialog box, the name is %xx



I see, but does the program that you use to open the file work correctly? If
yes I suppose you don't have to worry :-)


3.
>
> >>fileName = new String(fileName.getBytes("ISO-8859-1"), "UTF-8");
>
> I have done my jsp page  encoding as UTF-8 but i suppose my JVM or server
> specific encoding is ISO-8859-1

I need to do  String = new String(String.getBytes("ISO-8859-1"), "UTF-8");
> before storing anything to the oracle database
> otherwise it appears junk whenever i try to get it on the screen



The String class is encoding-independent, so maybe it is a problem of
correspondence between your JSP page header and the "meta" tag.
You have to set both:

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

and:

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

HTH
Antonio



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


Re: FileName characters.

Posted by Antonio Petrelli <an...@gmail.com>.
2007/5/8, Kapil Sharma <ka...@iap-online.com>:
>
> 2.
>
> The attachment dialog box shows correct filename.
> Also saving the file to my local disk also is correct
>
> But when i try to open the file directly on clik of "open" button from
> dialog box, the name is %xx



I see, but does the program that you use to open the file work correctly? If
yes I suppose you don't have to worry :-)


3.
>
> >>fileName = new String(fileName.getBytes("ISO-8859-1"), "UTF-8");
>
> I have done my jsp page  encoding as UTF-8 but i suppose my JVM or server
> specific encoding is ISO-8859-1

I need to do  String = new String(String.getBytes("ISO-8859-1"), "UTF-8");
> before storing anything to the oracle database
> otherwise it appears junk whenever i try to get it on the screen



The String class is encoding-independent, so maybe it is a problem of
correspondence between your JSP page header and the "meta" tag.
You have to set both:

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

and:

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

HTH
Antonio

RE: FileName characters.

Posted by Kapil Sharma <ka...@iap-online.com>.
1.

My
browser is IE 6.0
and
OS is windows 2000 professional


2.

The attachment dialog box shows correct filename.
Also saving the file to my local disk also is correct

But when i try to open the file directly on clik of "open" button from
dialog box, the name is %xx

3.

>>fileName = new String(fileName.getBytes("ISO-8859-1"), "UTF-8");

I have done my jsp page  encoding as UTF-8 but i suppose my JVM or server
specific encoding is ISO-8859-1

I need to do  String = new String(String.getBytes("ISO-8859-1"), "UTF-8");
before storing anything to the oracle database
otherwise it appears junk whenever i try to get it on the screen




Thanks and Regards,
Kapil Sharma
IAP Company Ltd.


-----Original Message-----
From: Antonio Petrelli [mailto:antonio.petrelli@gmail.com]
Sent: Tuesday, May 08, 2007 4:21 PM
To: Struts Users Mailing List
Subject: Re: FileName characters.


2007/5/8, Kapil Sharma <ka...@iap-online.com>:
>
> Hii
>
> I am using struts, jboss 4.0.1 and downloading file from the JSP as an
> atachment..
>
> My file has japanese and chinese characters...
>
> The problem is that when i m directly opening this file on the fly from
> the
> Dialog box by clicking on the open button, it is showing me some
> characters
> like %3s or something like.



Do you mean in the browser?
The %xx characters are special characters encoded for URLs.
By the way, what's your browser/operating system?


These characters are appearing file on the dialog box and also saving the
> file is OK but i don't know why they get something like while opening on
> the
> fly



Sorry, I can't understand. The opened file has the correct filename or not?
And the saved file?



> try {
>
> fileName = new String(fileName.getBytes("ISO-8859-1"), "UTF-8");



Why do you get bytes as ISO-8859-1 and reencode them as UTF-8? It does not
make sense!

Antonio



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


Re: FileName characters.

Posted by Antonio Petrelli <an...@gmail.com>.
2007/5/8, Kapil Sharma <ka...@iap-online.com>:
>
> Hii
>
> I am using struts, jboss 4.0.1 and downloading file from the JSP as an
> atachment..
>
> My file has japanese and chinese characters...
>
> The problem is that when i m directly opening this file on the fly from
> the
> Dialog box by clicking on the open button, it is showing me some
> characters
> like %3s or something like.



Do you mean in the browser?
The %xx characters are special characters encoded for URLs.
By the way, what's your browser/operating system?


These characters are appearing file on the dialog box and also saving the
> file is OK but i don't know why they get something like while opening on
> the
> fly



Sorry, I can't understand. The opened file has the correct filename or not?
And the saved file?



> try {
>
> fileName = new String(fileName.getBytes("ISO-8859-1"), "UTF-8");



Why do you get bytes as ISO-8859-1 and reencode them as UTF-8? It does not
make sense!

Antonio