class DownloadServlet extends HttpServlet {
private void getDownloadFile(final HttpServletRequest request, final
HttpServletResponse response) {
FileVO file =
fileService.getFile(request.getParameter("down").toString());
if (file == null) {
return;
}
String ua = getThreadLocalRequest().getHeader("User-Agent");
boolean isFirefox = (ua != null && ua.indexOf("Firefox/") != -1);
String uriEncoding = null;
try {
// I18N
uriEncoding = URLEncoder.encode(file.getFILE_NAME(), "UTF-8");
} catch (UnsupportedEncodingException e) {
}
if (isFirefox) {
response.setHeader("Content-Disposition", "attachment;
filename*==UTF-8''" + uriEncoding + "");
} else {
response.setHeader("Content-Disposition", "attachment; filename=" +
uriEncoding + "");
}
response.setHeader("Content-Length",
String.valueOf(file.getFILE_LONGBLOB_SIZE()));
try {
response.getOutputStream().write(file.getFILE_LONGBLOB());
response.getOutputStream().flush();
response.getOutputStream().close();
} catch (IOException e) {
log.error(e);
}
}
@Override
protected void doGet(final HttpServletRequest request, final
HttpServletResponse response)
throws IOException, ServletException {
if (request.getParameter("down") != null {
getDownloadFile(request, response);
}
}
}
2014-03-03 19:58 GMT+09:00 Davide Micheletti <[email protected]>:
> Hi all.. I need to know how to use DownloadServlet.. I tried to implement
> it but i don't understand how to continue the code.. here my implementation
>
> public class DownloadServlet extends HttpServlet{
> protected void doGet( HttpServletRequest req, HttpServletResponse resp )
> throws ServletException, IOException
> {
> String fileName = req.getParameter( "fileInfo1" );
>
> int BUFFER = 1024 * 100;
> resp.setContentType( "application/octet-stream" );
> resp.setHeader( "Content-Disposition:", "attachment;filename=" +
> "\"" + fileName + "\"" );
> ServletOutputStream outputStream = resp.getOutputStream();
> resp.setContentLength( Long.valueOf( getfile(fileName).length()
> ).intValue() );
> resp.setBufferSize( BUFFER );
> //Your IO code goes here to create a file and set to
> outputStream//
>
> }
> }
>
> what do i need now??.. Thanks in advance
>
> Davide
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google Web Toolkit" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/google-web-toolkit.
> For more options, visit https://groups.google.com/groups/opt_out.
>
--
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/groups/opt_out.