Hi Raj,
I look your code. I think, it does not work because you use not pure
сервлет for loading. I do not see heading of your class - similar that
it Faces PageBean?
I use a combination JSF pages + simple pure Servlet, listening part URL
for download:
public class Doc_view extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse
response)
throws ServletException, IOException {
String uri = request.getPathInfo();
int pdoc_id=Integer.parseInt(request.getParameter("doc_id"));
try {
response.setContentType("application/x-download");
response.setHeader("content-disposition", "attachment;
name=\""+downloadFileName+"\"; filename=\""+downloadFileName+"\"");
byte[] data = .... ;
response.setContentLength(data.length);
response.getOutputStream().write(data);
} catch (Exception e) {... }
}
Raj Saini wrote:
Hi Vladmir,
I tried your suggestion. It did not work for me. I am using apche my
faces JSF bridge. Does it work for you form a JSF based porlet?
Below the the code snipt of processAction method of command link
action listener. Can you see if I am missing something?
============================
FacesContext facesContext = FacesContext.getCurrentInstance();
String path =
facesContext.getExternalContext().getInitParameter("uploadDirectoryLocation");
Map map =
facesContext.getExternalContext().getRequestParameterMap();
String fileName = (String) map.get("fileName");
System.out.println("File URI: " + path+fileName);
File file = new File(path + fileName);
long fileSize =file.length();
//Set the HTTP headers for foce download the file
HttpServletResponse response =
(HttpServletResponse)FacesContext.getCurrentInstance().getExternalContext().getResponse();
response.setContentType("application/x-download");
response.setHeader("content-disposition",
"attachment;name=\""+fileName+"\";filename=\""+fileName+"\"");
response.setContentLength((int)fileSize);
==========================================================
Regards,
Raj
On 4/10/06, Vladimir Figurov <[EMAIL PROTECTED]> wrote:
Hi,
try next:
response.setContentType("application/x-download");
response.setHeader(
"content-disposition",
"attachment;name=\""+downloadFileName+"\";filename=\""+downloadFileName+"\"");
for me - it's worked exellent in IE, Opera and Mozilla
Raj Saini wrote:
Hi David,
I tried it. It does not work.
Thanks,
Raj
On 4/9/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
Hi,
try this code:
response.setContentType("binary/download");
response.setHeader("Content-disposition","attachment; filename=xxx.xxx");
before dump the content.
Best Regards,
David
-----Original Message-----
From: Raj Saini [mailto:[EMAIL PROTECTED]
Sent: Saturday, April 08, 2006 11:06 PM
To: Jetspeed Users List
Subject: Force downloading a file in JSF portlet
Hi,
I am building JSF based portlet for downloading a file using MyFaces JSF
bridge.
I do the following to make the file force download:
1) Set "content-disposition" header to contain the correct filename
2) Set "content-type" header to "application/octet-stream" or something more
accurate if the information is present in attachment metadata
3) Dump the content using a ServletOutputStream
When I click on the link to download the file, instead of throwing a dialog
box for saving/opening the file, browser dumps the the binary contents on
page. However, this works fine as standalone application.
Is there something extra I need to do to force download file in Jetspeed? Am
I missing something here?
Regards,
Raj
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
--
Vladimir
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
--
Vladimir
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]