Problem in file download dialog
Hi,
I am using the following code to download a PDF file. (Whiich is present in the database and I am retriving it using JDBC call).
InputStream in = null;
HttpServletResponse response = ctx.response();
response.setContentType ("application/pdf");
response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
in = (InputStream)requestHandler.read(rparams);
byte[] buf = new byte[4096];
int len;
while((len = in.read(buf)) > 0)
out.write(buf, 0, len);
in.close();
out.flush();
out.close();
response.flushBuffer();
Now when user is clicking on the specified link, file download dialog is coming, if user clicks on save the file is getting saved successfully but if user clicks on OK, it is giving the error, "There was an error opening this document. The file does not exist".
Could anyone tell me what may be the problem in the code?
Thanks in advance
Amit
Following code is returning the InputStream object:
Blob document = null;
QueryManager qm = null;
int status = -1;
InputStream dataStream = null;
String sqlReadDocument = "select document from opr_t_aw_documents where id='"+id+"' and end_date > sysdate";
log.debug("sqlReadDocument is "+sqlReadDocument);
try
qm = new QueryManager();
ArrayList inParams = new ArrayList();
ResultSet result;
result = qm.performPrepQuery(sqlReadDocument, inParams);
if(result != null)
while(result.next())
document = result.getBlob(1);
if(document != null)
dataStream = document.getBinaryStream();
and out is simply response.getOutputStream().
Please let me know in case you need any further info.
Thanks,
Amit
Similar Messages
-
Problem With File Download Dialog Box
Hi all,
I have jsp page that allows a user to export oracle data to excel.
I have these code in my page:
<%@ page contentType="application/vnd.ms-excel" %>
response.setContentType ("application/vnd.ms-excel");
response.setHeader ("Content Disposition",
"filename=\"historicalrate.xls\"");
I run the page and it popups a file download dialog box with Open and Save buttons.
When I click the Save button a Save As window opens with a hr.xsl file name and Microsoft Excel Workbook(*.xls) as save type. It is what I want.
The problem I have is when I click the Open button on the file download dialog box it displays data in excel format on a browser well. Then I click File > save as on browser's tool bar the Save As window pop up with no file name and a default Text(tab delimited)(*.txt).
I need the file name and Microsoft Excel Workbook(*.xls) as default save type.
Any help would be greatly appreciated.
Please help
ThanksI have the same problem with hui_ling.
When user click on "Open", Excel start and open excel file correctly but the file name on excel title bar. 'Cause the file name is in Japanese characters. Any one can help me?
Message was edited by:
TNTVN -
File download dialog box problem!
Hi,
How do you force file download message box to use specified file name instead of JSP or servlet name.
I am using:
// code in attachment.jsp
<%
response.setContentType(mimeType.trim());
response.setHeader("Content-Disposition","attachment;filename=\""+attachmentViewBean.getAttachmentName()+ "\"");
%>
With the above code, browser first pop up file download dialog box informing
'You are downloading the file:[attachment.jsp] from host. Would u like to open the file or save?'
I want the file name that I had specified in setHeader("Content-disposition","attachment;filename=resume.doc") to appear(i.e. resume.doc) in above dialog box and not the servlet name.
Any suggestions/tips on this?
Your help would be greatly appreciated.
Thanks,
YogeshFor saving the document I have used -
res.setHeader("Content-disposition", "attachment; filename="+ FileName );
and it is working very fine, it saves the document with name specified in FileName
For opening the file in browser without any prompt-
res.setHeader("Content-disposition", "inline" );
For setting the content type -
try {
if(FileType.equalsIgnoreCase("pdf")) contentType = "application/pdf";
if(FileType.equalsIgnoreCase("doc")) contentType = "application/msword";
if(FileType.equalsIgnoreCase("rtf")) contentType = "application/msword";
if(FileType.equalsIgnoreCase("gif")) contentType = "image/gif";
if(FileType.equalsIgnoreCase("jpg")) contentType = "image/jpeg";
if(FileType.equalsIgnoreCase("html")) contentType = "text/html";
if(FileType.equalsIgnoreCase("htm")) contentType = "text/html";
if(contentType == null){
contentType="text/plain";
res.setContentType(contentType);
} catch (Exception e){
out.println("Exception while setting content type");
out.println("Exception : " + e);
return;
Hope this helps -
Hi,
I am creating a site using struts framework. In that one I code one "Download" hyperlink. Which should download Excel file to the client site.
For this I want the Windows File Download Dialog Box to pop up when the user presses the "Download"
hyperlink on the page. This is the dialog box which prompts the user to either open the file or save
the file.
However, instead of File download dialog box, IE opens the text document within itself.
From what I understand, if the Mime Type of the file I am trying to open is registered on the client
workstation, then this dialog box wont pop up as Windows would automatically get the registered Mime
Type from the registry and open the application. For this we need to add headers to http response (content-disposition). Where to add this header info. In JSP, Action classes?
Can somebody help.
ThanksI am facing a similar problem...however in my case my application is on Tomcat server and when the user clicks the link, he/she sees junk data (excel sheet data) in plain html which makes no sense (with lot of special chars, just like opening any binary file in notepad)
while if i run the application in WSAD then the links work fine....is there any difference in both the servers in the way they treat file download? -
File download dialog box events and work around
Hi all,
I have a amall problem.
when i set content type and header for downloading a file which is generated from the server i get a "file download dialog box" (open/save/cancel)
but the problem is i cannot capture the events i.e. if the client clicks 'cancel' since i cannot capture 'cancel' i cannot do some other modifications that need to be done when the file is not downloaded.
is there any way which i can track if the file is actully downloaded by the client or not??
Or is there any way i can just by pass this dialog box and get a "save as dialog box" which enables him to choose a location directly download to his hard drive.(In this case i ll get a javascript confirmation before actully creating the file)
i am using IE6SP1.
Thanks in advance for your support.Just using JSP/HTML/Javascript code I don't think there is a way to do what you want. You might be able to do so using a Java Web Start application - like a download manager.
-
Orarrp, IE file download dialog screen always asks before opening
orarrp 1.3.4 working, but under IE5.5, the File Download dialog
screen is activated when the web.show_document(<url>,'_BLANK')
call is made, where the extension of the file is ".rrpa".
The checkbox which reads "Always ask before opening this type of
file" is checked and disabled. This means that user intervention
is always required.
When I open the .rrpa file directly in IE (the file is available
on a locally attached drive -- that is, not as a URL at this
point), IE opens and immediately prints the .rrpa file.
Obviously the restrictions here are based on internet security
settings, however, I've been unable to overcome this problem.
There do not seem to be options in IE, nor in the
characteristics of the file types themselves.
Question: How do I set my environment to enable the "Always
ask ...." check box, so it can be uncheck?I have no solution to my problem -- just more research results.
From MS's support database, article Q232077, IE has a
predefined, hard-coded list of file extensions that it
inherently distrusts, which results in the "Always ask before
opening" option to be checked and grayed out. The hard-coded
list does NOT include orarrp extensions (such as .rrpa), but
instead, extensions like .exe, .com, .bat, .cmd.
Nonetheless, ".rrpa" is still seems to be treated as a
permanently distrusted application -- I do not know why.
To quote the aforementioned article: "[T]he File Download dialog
box is not preventable in any way. This includes the use of HTML
tags, script in the page, hosting the WebBrowser control, and
changing security zone options."
The article does go on to describe IE/Windows only solutions:
<IFRAME> tag pointing to a shared Windows directory using MS's
UNC; and ActiveX/cab construction and deployment. Clearly,
neither is a solution.
I can't quite conclude that there is no solution under IE, but
its close. -
To display non US-ASCII filename in file download dialog - Help Needed
Hi,
Our application supports to upload a file with name in chinese/japanese language. When user tries to download filedownload dialog box is appearing with the filename as junk characters.
How to solve this issue to display the filename as uploaded.
Thanks in advance
~kansbsampieri, issue is in display of the file name in
file download dialog.
~kansI understood that, but my thought was that the HTTP headers content type containing a charset of UTF-8 might help. I don't know for sure, but otherwise, I don't know how to get the browser to otherwise not assume ASCII. -
In some thread, i had this problem with file download that instead of opening File Save..popup, the contents of file on the server were being rendered statically as HTML. I have figured out the solution to that but now the thing is in every file, there are some \n\r being added in the beginning of the file. Can anybody help. Here's is my code.
<%@ page import="java.io.*"%>
<%
try
response.setContentType("APPLICATION/OCTET-STREAM");
String strProjectInfoPageHeader = "Attachment;Filename=\"" + request.getParameter("txtProjectInfoPageFileName") + "\"";
response.setHeader("Content-Disposition", strProjectInfoPageHeader);
File fileToDownloadProjectInfoPage = new File(request.getParameter("txtProjectInfoPageFilePath"));
FileInputStream fileInputStreamProjectInfoPage = new FileInputStream(fileToDownloadProjectInfoPage);
int varProjectInfoPage;
while ( (varProjectInfoPage=fileInputStreamProjectInfoPage.read()) != -1 )
out.write(varProjectInfoPage);
out.flush();
out.close();
fileInputStreamProjectInfoPage.close();
catch(Exception e)
out.println(e);
%>Thanks and regards
VikramJSPs will invariably have newlines and whitespace in them, even if you don't explicitly put them. Instead of wasting time trying to fix it, just move your code to a servlet and map it to the same path. That's the fastest and most sensible solution. It also follows the convention that JSPs are to be used for display only and servlets for processing.
People on the forum help others voluntarily, it's not their job.
Help them help you.
Learn how to ask questions first: http://www.catb.org/~esr/faqs/smart-questions.html
---------------------------------------------------------------- -
Change File Name In The "File Download" Dialog Box For Web Reports
Hi All ,
I followed the below note to change the "File Download" name.
How To Change The File Name In The "File Download" Dialog Box For Web Reports? Doc ID: Note:418366.1
However its not working. Has anyone tried this and works fine ?
Basically I wanted to change the name "rwservlet" when a report is run in an
excel format.
Rajesh Alex
Rajesh AlexHello,
Have you checked if a HTTP header "Content-disposition" is returned ?
You can use ieHTTPHEaders for IE
http://www.blunck.se/iehttpheaders/iehttpheaders.html
and
Live HTTP Headers for FireFox
https://addons.mozilla.org/en-US/firefox/addon/3829
Regards -
File download dialog box -running report
I am calling one report from my Oracle 9i Developer Suite Application. When i call one report using 'delimited' format, the run runs okay opening in a new Internet Explorer(IE) instance. But, when i call another report, the File download dialog box -running report opens which asks whether u want to open the file or save it in your computer. I hope, my doubt is clear.Please help me in this as it is very urgent.
Regards.This is a duplicate post. Please followup on your previous posting.
What is the URL you specify? -
File Download Dialog shown unexpectedly on submit (ADF)
We are getting an issue using ADF v10.1.3.0.4 where the File Download Dialog is being shown by the browser when a user clicks a navigation button or the date picker button. It doesn't happen consistently but often enough to be a issue for us. The download dialog asks the user to download the *.faces page rather than just displaying it! If they click cancel and then click the button again then the page is usually displayed correctly. We are running over SSL and using IE6 SP2. Has anyone seen this before and if so what is the solution to fixing it?
Thanks, JMHi,
actually I did run my test app via SSl as wellbut this effect didn't show. You could try and upgrade to a recent version of JDeveloper to see if it reproduces there. Or customer support at metalink.oracle.com is an option to solve the issue.
Frank -
Seeing multiple file download dialogs trying to download one file.
I'm seeing some strange behavior from an application that uses the Safari Webkit to download a file from within the app. When I click the 'download' button I get cascading file download dialog boxes. Sometimes it is only two and sometimes it is 15+. Has anyone ever heard of this before????? Could it potentially be related to Java script or the version of Java?
Thanks!Yes I've been in contact with the developer and they aren't sure what the issue could be as it seems to be happening for only a few users. From what they can tell it is only on Leopard. They use an SDK that calls into the Safari webkit, so they thought it might have something to do with my Safari preferences.
-
Urgent!!how to open the file download dialog box????
Hi all,
i'm using the browse button for the user to select the file
and a submit button, which when cliked should open the file
download dialog box asking for open or save.
i searched for so many forums and websites and didn't get the
solution yet.
i'm using jsp.
anyone have the jsp code for the same????
will b more helpful if u send it to me.
thanx in advance.Hi
Use the Filedialog class.
Let your button call a method wich contains the following Java code:
FileDialog filedialog =
new FileDialog( Frame1.this, "Open a File", FileDialog.LOAD );
//witch calls this constructor: public FileDialog(Frame parent, String title, int mode)
//use Filedialog.SAVE to save a file.
filedialog.show();
String filename = filedialog.getFile();//to display the name of the file
String directoryname = filedialog.getDirectory();// to display the directory name -
How to get file download dialog box in IE 6.0 for .CSV files?
In our Java application, when we download .csv file (by clicking a tool bar button or menu item) in IE 5.5, it brings up the download dialog box and when we click the open button it opens the file in a seperate browser window but after migrating to IE 6.0 it doesn't bring the download dialog box and we are not able to open the excle sheet in a new browser window.
We tried downloading .csv file in IE 6.0 by changing its extension(such as .cs1 and .xls) even then it did not work.We also tried associating CSV type of extension with "Microsoft Excel Comma Separated Values File" in the Windows folder options (Windows Explorer->tools->folder options->file types(tab)), which did not work.
Please respond if you have come across this kind of issue and solution for the same.
Thanks in AdvanceThis has nothing to do with Java. It's Microsoft
setting for known file type. IE is responding to the
setting which will automatically download known file
type (MIME type).
To show the "Save As" file dialog, you have to do the
following (for each file type)
1. open Window Explorer
2. click on Tool-->"Folder Option"
3. click on the "File Type" tab
4. select the extension and then click on the
"Advance" button
5. Check the "Confirm open after download" checkbox
6. Click OK
IE should now display the "Save As" file dialog for
that extension. Remeber, you have to to this for all
extension you want to see a "file dialog" pop up.Unfortunately this is not the only cause. Even with this box checked, downloading java source files from the pages of The Java Tutorial causes them to open in the most recent IE - I (and others also) don't get the save/open dialog box. Java source files downloaded from (some) other websites result in the save/open dialog box. I believe that one of the security changes that MS made in IE's handling of files is the cause. The setting of content-disposition by the server appears to be the key, according to MSDN information. -
I am using Fire Fox 5 beta version. After pausing the long file download, when I press the Resume download button the above message appear each time asking "Contact to Administrator". This problem was not with Fire Fox version 3 and above. Please Help Immediately. Thanks in advance...
It is possible that your anti-virus software is corrupting the downloaded files or otherwise interfering with downloading files by Firefox.
Try to disable the real-time (live) scanning of files in your anti-virus software temporarily to see if that makes downloading work.
* http://kb.mozillazine.org/Unable_to_save_or_download_files
Maybe you are looking for
-
How can I see any files that did not originally come on the mac
I downloaded and erase a few things here and there and ever since I did that I feel a slight differnce in the power of my book.. and I am completely new to mac so I am not sure how to navigate through everything completely just yet. I know how to use
-
QuickTime plug-in for Window Media Files?
Microsoft recently announced that they will stop developing any update or improvement for Window Media Player for the Mac: http://news.yahoo.com/s/ap/20060113/apon_hi_te/microsoftapple It is a little disappointing aspect because sometimes I keep runn
-
COPA Report: I am trying to execute a Profitability Report using Tcode KE30. After giving the input details, one pop-up appears "Save XXL Object in SAP Office" Two input fields : "Name for list object" & "Title for SAP Office" If I give name & title
-
Hello I just loaded my CS3 onto a Windows7 laptop and when I go into performance to set how much memory for it to use it is showing just shy of 3 GBs. The computer has 8GBs of memory. The old Vista computer showed relatively the same memory and it ha
-
In my enviornment i have 2 custom entities wiht N:1 Relation Once I clicks on the sub-grid of choice contract on the supplier form, the user still gets the contract records instead of choice contract record. whether this is by design or the settings