You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Владимир Петров <vp...@list.ru> on 2007/08/25 21:34:47 UTC

Russian characters of a filename in the dialogue to open or to save the file, turn to hieroglyphs. (tomcat apache Myfaces)

Hello! I'm from Russia. And I not so well speak in English. i am trying to get the data from database to jsp. If the name of the file on English - in the dialogue normal characters, all works. If the name of the file on Russian - in the dialogue hieroglyphs and nothing works. Please respond.
jsp:

<%@ page contentType="text/html; charset=UTF-8" %>
<%@ page pageEncoding="UTF-8"%>
<%@ page import="java.io.File,
                 java.io.InputStream,
                 java.io.FileInputStream,
                 java.io.OutputStream"%>
<%@ page session="false" %>
<%
    String fileName = (String)application.getAttribute("fileupload_name");
    String contentType = (String)application.getAttribute("fileupload_type");
    if(contentType!=null){
        response.setContentType(contentType);
    }
   
    StringBuffer contentDisposition = new StringBuffer();
    
    contentDisposition.append("attachment;");
    //URLEncoder.encode(fileName, "UTF-8");
    contentDisposition.append("filename=\"");
    contentDisposition.append(fileName);
    contentDisposition.append("\"");
 
    response.setHeader ("Content-Disposition", contentDisposition.toString());
    
    
    byte[] bytes = (byte[])application.getAttribute("fileupload_bytes");
    if (bytes != null){
        response.getOutputStream().write(bytes);
    }
%>

Thank by all.

Re: Russian characters of a filename in the dialogue to open or to save the file, turn to hieroglyphs. (tomcat apache Myfaces)

Posted by Volker Weber <v....@inexso.de>.
Hi,

to get the correct encoded filename i do this:

      String encoding = request.getCharacterEncoding();
      if (encoding == null) {
        encoding = "UTF-8";
      }
      String fileName = new String(attachment.getName().getBytes(), encoding);


Regards,
    Volker

2007/8/25, Владимир Петров <vp...@list.ru>:
> Hello! I'm from Russia. And I not so well speak in English. i am trying to get the data from database to jsp. If the name of the file on English - in the dialogue normal characters, all works. If the name of the file on Russian - in the dialogue hieroglyphs and nothing works. Please respond.
> jsp:
>
> <%@ page contentType="text/html; charset=UTF-8" %>
> <%@ page pageEncoding="UTF-8"%>
> <%@ page import="java.io.File,
>                  java.io.InputStream,
>                  java.io.FileInputStream,
>                  java.io.OutputStream"%>
> <%@ page session="false" %>
> <%
>     String fileName = (String)application.getAttribute("fileupload_name");
>     String contentType = (String)application.getAttribute("fileupload_type");
>     if(contentType!=null){
>         response.setContentType(contentType);
>     }
>
>     StringBuffer contentDisposition = new StringBuffer();
>
>     contentDisposition.append("attachment;");
>     //URLEncoder.encode(fileName, "UTF-8");
>     contentDisposition.append("filename=\"");
>     contentDisposition.append(fileName);
>     contentDisposition.append("\"");
>
>     response.setHeader ("Content-Disposition", contentDisposition.toString());
>
>
>     byte[] bytes = (byte[])application.getAttribute("fileupload_bytes");
>     if (bytes != null){
>         response.getOutputStream().write(bytes);
>     }
> %>
>
> Thank by all.
>

Re: Russian characters of a filename in the dialogue to open or to save the file, turn to hieroglyphs. (tomcat apache Myfaces)

Posted by David Delbecq <de...@oma.be>.
Здравствуйте Владимир!

did you try response.setContentType("application/bin; charset=utf-8"); ?

The main problem is that http header field value only accept brute 
ISO-8859-1, which does not contains cyrilic i think.
According to http specification, it "MAY contain characters from 
character sets other than ISO- 8859-1 [22] 
<http://www.w3.org/Protocols/rfc2616/rfc2616-sec17.html#bib22> only when 
encoded according to the rules of RFC 2047".

I suppose tomcat should do it itself, but i never tried. If not, you may 
need to do i your self by applying rfc 2047 rules to your filename and 
hope your browser supports it :D

http://www.ietf.org/rfc/rfc2047.txt


Владимир Петров a écrit :
> Hello! I'm from Russia. And I not so well speak in English. i am trying to get the data from database to jsp. If the name of the file on English - in the dialogue normal characters, all works. If the name of the file on Russian - in the dialogue hieroglyphs and nothing works. Please respond.
> jsp:
>
> <%@ page contentType="text/html; charset=UTF-8" %>
> <%@ page pageEncoding="UTF-8"%>
> <%@ page import="java.io.File,
>                  java.io.InputStream,
>                  java.io.FileInputStream,
>                  java.io.OutputStream"%>
> <%@ page session="false" %>
> <%
>     String fileName = (String)application.getAttribute("fileupload_name");
>     String contentType = (String)application.getAttribute("fileupload_type");
>     if(contentType!=null){
>         response.setContentType(contentType);
>     }
>    
>     StringBuffer contentDisposition = new StringBuffer();
>     
>     contentDisposition.append("attachment;");
>     //URLEncoder.encode(fileName, "UTF-8");
>     contentDisposition.append("filename=\"");
>     contentDisposition.append(fileName);
>     contentDisposition.append("\"");
>  
>     response.setHeader ("Content-Disposition", contentDisposition.toString());
>     
>     
>     byte[] bytes = (byte[])application.getAttribute("fileupload_bytes");
>     if (bytes != null){
>         response.getOutputStream().write(bytes);
>     }
> %>
>
> Thank by all.
>