How to set UTF-8 encoding for a file download servlet.

382 views
Skip to first unread message

nacho

unread,
Dec 28, 2010, 10:44:43 PM12/28/10
to Google App Engine
I have a servlet that sends a file to the browser, i get the data from
the datastore.

I send this headers in the servlet.

if (request.isSecure()) {
response.addHeader("Pragma", "no-cache");
response.addHeader("Expires", "-1");
response.addHeader("Cache-Control", "no-cache");
} else {
response.addHeader("Cache-Control", "private");
response.addHeader("Pragma", "public");
}

if (isIE) {
response.addHeader("Content-Disposition", "attachment;
filename=\"" + encName + "\"" );
response.addHeader("Connection", "close");
response.setContentType("application/force-download; name=
\"" + encName + "\"" );
} else {
response.addHeader("Content-Disposition", "attachment;
filename=\"" + encName + "\"" );
response.setContentType("application/octet-stream; name=\"" +
encName + "\"" );
if (contentLen > 0) {
response.setContentLength(contentLen);
}
}

Then i send the file to the browser, but i'm having troubles with the
file encoding.

For example, in the downloaded file i get a line like this

howDoesItWorksStep21Description=El usuario elige la operadora de su
tel??fono m??vil.

But the data is stored right in the datastore ("El usuario elige la
operadora de su teléfono móvil.")

Does anyone have idea how can i do to fix it? Am I missing any header?

Stephen Johnson

unread,
Dec 29, 2010, 12:54:04 AM12/29/10
to google-a...@googlegroups.com
Have you tried using the

setCharacterEncoding("UTF-8");

method on the response object.


--
You received this message because you are subscribed to the Google Groups "Google App Engine" group.
To post to this group, send email to google-a...@googlegroups.com.
To unsubscribe from this group, send email to google-appengi...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en.


Reply all
Reply to author
Forward
0 new messages