tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sylvie Perrin <sylvie.per...@continew.fr>
Subject Create FileInputStream in servlet from remote file with accentuated character name
Date Thu, 17 Sep 2009 13:12:47 GMT
I have a problem with Tomcat 6.0 on Linux and I haven't been able to 
determine the cause or solution.

I have a shared directory on a windows system named SHAREDDIR and 
containing one file named "fichié.txt"
I mount this shared directory on my Linux system with the following command:
 > mount -t cifs -o iocharset=utf8 //IpWindows/SHAREDDIR /home/me/mountDir/

In a standalone Java application running on my Linux system, I can 
create a FileInputStream from the file located in the remote directory 
like this:

String mountPath = "/home/me/mountDir";
File[] list = new File(mountPath).listFiles();
File file = list[0];
try {
    FileInputStream fStream = new FileInputStream(file);
}
catch (FileNotFoundException e) {
    e.printStackTrace();
}

When I execute the same code in a servlet running on the same machine, 
the call to FileInputStream constructor always throws a 
FileNotFountException because it  doesn't recognize the "é" character in 
the path of the file.
When I rename my file on my windows shared directory in "fichie.txt", 
the servlet is executed without any errors.

Since I don't know what the problem is I have had a hard time tracking 
down a solution online. I especialy take care to follow all steps 
described in the FAQ/CharacterEncoding parts of wiki. Here is my 
configuration:

I set URIEncoding in my port 8080 connector to UTF-8 (I use this port to 
execute my servlet)
<Connector port="8080" protocol="HTTP/1.1"
   connectionTimeout="20000"
   redirectPort="8443"
   URIEncoding="UTF-8"
   useBodyEncodingForURI="true" />

I use a filter to set the default encoding to UTF-8 and my first line of 
my doFilter method is
 request.setCharacterEncoding("UTF-8");

I add in my servlet the set of content-type for responses to UTF-8 and 
my first line of my doGet method is
 response.setContentType("text/html;charset=UTF-8");

My tomcat is started with CATALINA_OPTS=-Dfile.encoding=UTF-8

My servlet displays some debug traces and I verify that Servlet response 
getCharacterEncoding = UTF-8 and Servlet request getCharacterEncoding = 
UTF-8

Any idea why FileInputStream doesn't work in a servlet?

Thanks



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message