JSP, downloading files and show html page

I like to download files and show a html page on JSP.
With the source following, downloading works well.
But, it is just remained on the previous page, not showing the next html page.
Someone tell me why is it?
<%@ page import="java.io.*, java.net.URL"%><%
String file_name = request.getParameter("file_name");
File fileDir = new File(config.getServletContext().getRealPath("upload/"));
File theFile = new File(fileDir, file_name);
FileInputStream fin = new FileInputStream(theFile);
response.setHeader("Content-Disposition","attachment; filename=\"" + theFile.getName()+"\"");
response.setContentLength((int) theFile.length());
BufferedInputStream bf = new BufferedInputStream(new FileInputStream(theFile), 8096);
int i;
while ((i=bf.read()) != -1)
out.write(i);
bf.close();
out.close();
%>
<html>
<head>
<title>file download</title>
</head>
<body>
<p align="center"> </p>
<p align="center"><b><font face="Tahoma" color="#000000" size="2">You have
successfully downloaded your file(<%=file_name%>)!</font></b></p>
</body>
</html>

You's already close the JSP output stream befor you try and write your html confirmation, and I don't think browsers can provide the kind of functionality you're trying to demonstrate here. A browser will download the file and open it directly itself or using another application based on user input (e.g. save as, open file, etc.). Once the file is opened or downloaded, it's done!
I think your best bet is to show a dialogue that the user's download should begin, then set the pages href w/ JS to the location of the file, same way other sites that allow you to download files do it. Go take a look at download.com or something like that.
Hope that helps.

Similar Messages

  • Upload a file and show in JPS !!!

    I want to upload a particular file which is consisted of some datas and separated by commas. I want to upload that particular file and show to the next jsp page. I'm not using the database. The delimiter are "," and "\n". It can be easily done by using database but i don't want to use the database.
    could anyone halp me out.....
    in advance thanks....

    I want to upload a particular file which is consisted
    of some datas and separated by commas. Okay, try Google for simple file upload examples.
    I want to
    upload that particular file and show to the next jsp
    page. Okay.
    I'm not using the database. Okay.
    The delimiter are
    "," and "\n". Huh?
    It can be easily done by using database
    but i don't want to use the database.It can be easily done a few ways. Database has nothing to do with anything here, it's just one way to store data.

  • How do you have 2 Safari windows open and show both pages simultaneously on the monitor

    How do you keep open 2 Safari windows and show both pages on monitor?

    While in Safari with your first window open go to the File menu and select New Window. That will open the second window on which you can navigate to your second web page. Resize both windows to fit on your display.

  • How to display a text file in a html page?

    I have written a servlet that executes a batch file whose output is saved to a txt file. I am attempting to display content of the text file as a html page from the servlet but am struggling I have attempted to read the file and output it as shown below but it is not displaying the correct data
    Appreciate some help
    Thanks in advance
    Amjad
    Runtime r = Runtime.getRuntime();
    Process p = r.exec("C:\\Condor\\test\\QueStatus.bat");
    PrintWriter out;
    String title = "Que Status";
    response.setContentType("text/html");
    out = response.getWriter();
    FileReader fr = new FileReader ("C:\\Condor\\test\\output.txt");
    for (int chr = fr.read(); chr != -1; chr = fr.read()){
         out.print(chr);
    }

    Couple of things. First you should search the forums for how to properly exec a dos batch file. There are some problems you may run into especially with io. I suspect you may not actually be running that batch file at all.
    I would test outputing a text file separately from execing the batch file.
    Here is some code so you don't have to output 1 char at a time. Setting the content length and closing the output stream might help.
    File downloadFile = new File("c:\\blah\\blah\\blah");
    response.setContentLength((int)downloadFile.length());
    response.setContentType("text/html");
    ServletOutputStream out = response.getOutputStream();
    FileInputStream fis = new FileInputStream(downloadFile);
    byte[] buffer = new byte[1024];
    int bytesRead;
    while ((bytesRead = fis.read(buffer)) != -1) {
    out.write(buffer, 0, bytesRead);
    fis.close();
    out.close();

  • Servlet showing HTML page

    I ma using Tomcat as standalone server.
    have servlet showing HTML page which has frames in it . All frames are linked to some html pages. These pages are stored in
    webapps/project directory and servlet is in
    \Tomcat 4.1\webapps\Project\WEB-INF\classes
    Tomcat can show the servlet with al frames witherror402 means it is unable to take html pages from webapps/project
    what's wrong
    my codes are
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class Htmlservlet extends HttpServlet {
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException,IOException {
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    out.println("<HTML>\n"+
    "<HEAD> <TITLE>A frameset document</TITLE></HEAD>\n"+
    "<FRAMESET rows= \"20%,40%,40%\" >" +
    "<FRAME src=\"contents_of_frame3.html\" frameborder=\"0\" scrolling =\"no\">"+
      "<FRAMESET cols=\"*,200\">"+
          "<FRAME src=\"contents_of_frame1.html\" scrolling=\"no\">"+
          "<FRAME src=\"contents_of_frame2.gif\" >"+
    "</FRAMESET>"+
      "<FRAME src=\"contents_of_frame4.html\" frameborder=\"0\"> </FRAMESET>"+
    "</HTML>");
    }

    Hi,
    Please please try this
    <FRAME src=\"/contents_of_frame1.html\"
    thanks,
    nvseenu

  • I purchased creative lightroom presets. I see the zip file in my download file and I try to import to LR but it just keeps creating a bundle never giving me the option to import (greyed out). What am I doing wrong?

    I purchased creative lightroom presets. I see the zip file in my download file and I try to import to LR but it just keeps creating a bundle never giving me the option to import (greyed out). What am I doing wrong?

    Try unzipping the file first. I have no idea regarding your level of technical expertise so advanced apologies if this is really basic. A ZIP file is a compressed file containing one of more files within it. To access the files you will need to expand it. If you double-click on it first, it should open up for you. If it does not automatically expand, you can select the files and copy them to a new folder. The copy will unload them into an uncompressed form. Once they have been uncompressed, you should be able to import them.
    If the import is still giving you problems, go to your Preferences, click on the Presets tab and click the Show Presets Folder button. You can then copy your purchased presets into the folder shown. You will want to copy them to the User Presets subfolder.

  • How to not append '.PART' to the file name of the currently downloading file, and just download the file with its normal filename

    In Windows, when Firefox (I'm currently using 7.0) downloads a file, it appends ''.PART'' to the file name of the currently downloading file and just renames it to its original file name after it finishes downloading.
    I sometimes like to watch a currently downloading video file, so it will be better if Firefox just downloads the file to its actual filename (like what Opera does), so I can easily double click the incompletely downloaded file and watch it with the video player assigned to that file extension, rather than the awkward ''Right click -> Open With -> Choose Default Program'' route with .part files.
    Does anyone know how to set Firefox to do this?

    It is possible that your anti-virus software is corrupting the downloaded files or otherwise interfering with downloading files by Firefox and prevents Firefox from renaming the .part file.
    Try to disable the real-time (live) scanning of files in your anti-virus software temporarily to see if that makes downloading work.
    See "Disable virus scanning in Firefox preferences - Windows"
    * http://kb.mozillazine.org/Unable_to_save_or_download_files

  • How to upload file and show it's progress

    hi
    i want to upload files and show the progress of the upload
    process how?
    thanks in advance.

    Hey,
    I attached a sample I did in Flash 8 using PHP. Hope it
    helps.
    http://www.cybercussion.com/vault/fileuploading.zip

  • Sony 50mm f1.4 ZA SSM Lens Profile in 8.4 RC  any way I can download file and load into Lightroom ?

    Sony 50mm f1.4 ZA SSM Lens Profile in 8.4 RC  any way I can download file and load into Lightroom ?

    Short answer. No.

  • Difference(s) in usage of a ".json" bookmark backup file and a ".html" bookmark file

    Hello to all,
    What is the difference between usage of a ".json" bookmark backup file and a ".html" bookmark file? It seems both of them are doing the same job. If it is the case, then why there are two options (.json and .html) for doing the same job? If not, then what is the reason behind availability of the two options and how do they differ? Although I've read all the related documentaion, it's not quite clear form me yet. Please be kind enough to elaborate on the question so that I can get a clear understanding of their right usage(s).
    Thank you very much in advance for your time and expertise

    Hello,
    See [https://support.mozilla.org/questions/684284#answer-18836 questions/684284]

  • Compare two .txt files and show result

    HI
    Could anybody show me how to compare two text files and show the result.
    i.e.
    textfile1.txt
    harry.denmark
    karry.sweden
    textfile2.txt
    harry.denmark
    karry.sweden
    marry.usa
    Compare
    result=
    marry.usa
    The text files I want to compare are how ever much larger than this example. (up to 2-3.000 words)
    anybody ??
    Sincerly
    Peder

    HI & thanks for reply
    I know almost nothing about java so could you or anybody please show me the code to do this? Or is it perhaps too large or difficult a code?
    I know how to compile a .java file and run it in prompt :-) and thats about it (almost)
    I offcourse understand if its too much to ask for :-)

  • I have itune 10.5 with windows 7, when i click itune store it is not connected and show blank page

    I have itune 10.5 with windows 7, when i click itune store it is not connected and show blank page.

    You can't, Anh.  That's what people are telling you.  At this time there's no way to get out of recovery mode.   You're playing around with beta software and this is what you get.
    Tell your "developer friend" he needs to talk to other developers to see if this can be fixed, or have him replace your devices that you should never have let him play with to begin with.

  • I am using IFrame and displayed Html page

    Hi Friends
                        I am using IFrame and displayed Html page in flex4
                        In this page open to Firefox But not IE please help me.
                          Thanks
                           V.ChandraSekhar

    You have deleted your page, but you have not deleted your page?
    Which is it?
    If you never saved it it is gone. If you saved it in Lion (OSX 10.7) with Pages 09 v4.1, there should be versions available when you mouse overv the document name at the top of the window.
    Peter

  • Last update to itunes wiped out all downloaded files and playlists....NOT IMPRESSED!! Any ideas??

    Last update to Itunes wiped out all downloaded files and playlists. Not Impressed. Been searching for resolutions...everywhere. No such luck.....tried everything other than looking in the pc's registry.....not sure how to pull that off , but itunes is bugging me with these updates.....HELP!!! Lots of lost money here and no help.

    See Empty/corrupt library after upgrade/crash.
    tt2

  • Download files and videos

    Hi every one,
    I want best app that allow me to download file and videos vis safari browser
    I found some apps but all of them work out of safari browser.
    And, after some search i found ( safari download manager ) app it's work with safari browser
    But it's available only in sydia . See it :
    http://cydia.saurik.com/package/net.howett.safaridownloader
    Please help, thanks

    Please ask your question on a forum for the Flash Player

Maybe you are looking for

  • Case id-4615052271.

    Hi,CCHSAP191092 .As i am facing lot of trouble with my Laptop. My name is smruti sanjeeta jena and i have purchased the hp laptop dv series, so i can work and as HP is the best brand, but from the starting i am facing lot of difficulties. as you can

  • Where can I download Firefox 9.0?

    I am just wondering where I can download Firefox version 9 - other users have downloaded it but I perform an update check it says Firefox 8.0 is up to date plust the mozilla website still has version 8.0.1 listed.

  • Why do we use Unserialized V3 update for Inventory Management?

    Hello Experts, I have question on LO Cockpit extractor. Why do we use Unserialized V3 update for Inventory Management (2LIS_03_BF) ? Are there any reasons behind? thanks a lot Padma

  • Authorization error when logon to IB-Repository and Directory

    Hi, we patch from SP12 to SP13. At SP12 logon to IB (Repsoitory and Directory) work without problems. But after applying SP13 to XI we can't logon to IB anymore. The error is "Authorization error, unknown user name or incorrect password". The user we

  • Desktop Software & 9720 Sync Error Message

    When I sync my 9720 with my pc using DTS  I'm getting the following error message: Blackberry Desktop Software X Synchronisation Error A program error occurred at line 604 in .\Mapping cpp.  Please report this error by sending a log to technical supp