views:

9

answers:

0

Hi everyone, I have file with its name in japanese and i want to download it by using a request to servlet. When the link is clicked on the browser for file downloading, the name of the file displayed by the browser(firefox in this case) is not japanese but a combination of characters from english charset and also the size of file is shown as 0kb. here is my servlet code. The downloading for english filenames is doing fine, any other language it fails.

public class DownloadServletAny extends HttpServlet {

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

ServletOutputStream op = response.getOutputStream(); File f = new File("テスト");

int length = 0; ServletContext context = getServletConfig().getServletContext();

String fileName = f.toString(); String strAbsolutePath = context.getRealPath("");

response.setContentType("application/octect-stream");

response.setContentLength( (int)f.length() );

response.setHeader("Content-Disposition","attachment;filename="fileName);

String file = strAbsolutePath "/" + fileName; byte[] bbuf = new byte[1024];

FileInputStream fileInpStrm = new FileInputStream(file); while ((fileInpStrm != null) && ((length = fileInpStrm.read(bbuf)) != -1)) { op.write(bbuf,0,length); }

fileInpStrm.close(); op.flush(); op.close(); } }

Thankx in advance.