Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Help needed in excel download...

  1. #1
    Junior Member
    Join Date
    Feb 2010
    Thanked 0 Times in 0 Posts

    Default Help needed in excel download...

    Hi all,
    Am trying to download an excel kept in the server by java servlet. On click od download button, download dialog box appears and on clicking on save, the file gets downloaded and saved successfully. Everything in this is perfect. But on click of open button i want my excel to be opened in separate excel instead of opening the excel as embedded in the browser itself. Any guidelines would help me a lot. here is the code.. Am passing the file's path which is to be downloaded from jsp and getting the path in this servlet.

    Should i have to use jexcel for writing into excel separately and pop up on click of open?? is fo, can anyone explain with an example??

    public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
    String filename = request.getParameter("fileName");
    String fileDisplayName = filename.substring(filename.lastIndexOf("/")+1);
    String dataFileLocation = "C:\"
    File f = new File(dataFileLocation+"\\"+filename);
    response.setHeader("Content-Disposition", "inline; filename="+fileDisplayName);
    response.setHeader("Pragma", "public");
    response.setHeader("Cache-Control", "no-store");
    response.addHeader("Cache-Control", "max-age=0");
    FileInputStream fin = null;
    try {
    fin = new FileInputStream(f);
    } catch (FileNotFoundException e) { e.printStackTrace();}
    int size = 1024;
    try {
    byte[] buffer = new byte[size];
    ServletOutputStream os = null;
    os = response.getOutputStream();
    int length = 0;
    while ((length = fin.read(buffer)) != -1) {
    os.write(buffer, 0, length);
    } catch (IOException e) { e.printStackTrace();}

  2. #2
    Super Moderator Json's Avatar
    Join Date
    Jul 2009
    Warrington, United Kingdom
    My Mood
    Thanked 156 Times in 152 Posts

    Default Re: Help needed in excel download...

    Yes, change this.

    response.setHeader("Content-Disposition", "inline; filename="+fileDisplayName);

    to this:

    response.setHeader("Content-Disposition", "[b]attachment[/b]; filename="+fileDisplayName);


    // Json

  3. #3
    Junior Member
    Join Date
    Feb 2010
    Thanked 0 Times in 0 Posts

    Default Re: Help needed in excel download...

    Nope.. tried that one also.. it wasnt working.. Should we have to populate the excel workbook dynamically for this using POI or jexcel?? I have no idea on that..

Similar Threads

  1. Importing excel data
    By supriya ramjee in forum File I/O & Other I/O Streams
    Replies: 11
    Last Post: October 20th, 2012, 09:39 AM
  2. How to Download a file via FTP
    By JavaPF in forum Java Networking Tutorials
    Replies: 1
    Last Post: December 24th, 2011, 11:56 AM
  3. conversions and excel
    By mkslt4 in forum Java Theory & Questions
    Replies: 2
    Last Post: February 10th, 2010, 01:54 AM
  4. Facing problem with posting Excel file for download - Content in browser
    By ragz_82 in forum JavaServer Pages: JSP & JSTL
    Replies: 1
    Last Post: February 9th, 2010, 08:28 AM
  5. Export to excel
    By ebosysindia in forum File I/O & Other I/O Streams
    Replies: 7
    Last Post: May 14th, 2009, 06:25 AM