Results 1 to 1 of 1
Thread: problem with utf-8 encoding
- 03-05-2012, 08:27 AM #1
Member
- Join Date
- Dec 2011
- Location
- Tbilisi (Georgia)
- Posts
- 24
- Rep Power
- 0
problem with utf-8 encoding
i deploying application on tomcat server and i use to download file servlet wich calling procedure is
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String reportName = request.getParameter("reportName");
String reportType = request.getParameter("reportType");
String filename = URLDecoder.decode(reportName + "." + reportType, "UTF-8");
String resourcePath = request.getSession().getServletContext().getRealPa th("resources");
String systemPath = System.getProperty("catalina.base");
File file = new File(systemPath + "\\Reports\\", filename);
response.setHeader("Content-Type", getServletContext().getMimeType(file.getName()));
response.setHeader("Content-Length", String.valueOf(file.length()));
response.setHeader("Content-Disposition", "inline; filename=\"" + file.getName() + "\"");
BufferedInputStream input = null;
BufferedOutputStream output = null;
try {
input = new BufferedInputStream(new FileInputStream(file));
output = new BufferedOutputStream(response.getOutputStream());
byte[] buffer = new byte[8192];
for (int length = 0; (length = input.read(buffer)) > 0;) {
output.write(buffer, 0, length);
}
} finally {
if (output != null) {
try {
output.close();
} catch (IOException ignore) {
}
}
if (input != null) {
try {
input.close();
} catch (IOException ignore) {
}
}
}
}
its working fine but, its not returning correct file name when i have non latin alphabet
but when i adding this "response.setCharacterEncoding("UTF-8");"
i getting error "Exception Details: java.nio.charset.MalformedInputException
Input length = 1"
anybody can help me? why i getting error when i adding encodding utf-8?
Similar Threads
-
Problem with Encoding
By agajantorayev in forum Advanced JavaReplies: 7Last Post: 02-28-2011, 07:47 PM -
problem in encoding
By jaysh in forum NetBeansReplies: 0Last Post: 08-26-2010, 08:07 AM -
Problem with Base64 encoding
By Smirgu in forum Advanced JavaReplies: 1Last Post: 04-15-2010, 11:05 AM -
Encoding Problem
By GJ! in forum Advanced JavaReplies: 6Last Post: 01-12-2010, 08:09 PM -
Lucene Indexer Encoding problem
By svirid in forum LuceneReplies: 5Last Post: 02-18-2009, 09:26 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks