Results 1 to 12 of 12

Thread: Save Dialog

  1. #1
    Enthiran is offline Member
    Join Date
    Dec 2010
    Posts
    10
    Rep Power
    0

    Question Save Dialog

    Hi,

    I have java class file which creates a excel sheet. This file is called from a web application.Now i need to display the "SAVE DIALOG" in the web page which is displayed after the java file is executed.

    I need to save that excel file which is created in the java file, using the save dialog, via the Web page.Is there a way that i can do it in the java file or should i mess around with the jsp file.
    Last edited by Enthiran; 01-05-2011 at 10:27 AM.

  2. #2
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,016
    Rep Power
    20

    Default

    What do you mean by "save the excel file"?

  3. #3
    Enthiran is offline Member
    Join Date
    Dec 2010
    Posts
    10
    Rep Power
    0

    Default

    excel workbook actually.If i generate a excel workbook using fout in the java file it is saved in the default location of TomCat. So i need a save dialog so that i choose a place to save the file.

    Is there a way that i can do it from a java file. The UI is jsf about which i dont have any idea.

  4. #4
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,016
    Rep Power
    20

    Default

    That's an unusual requirement.
    You would normally not let the user of a webapp define where on the server to save files.

    But, you could simply ask the user for a file location at the same time as they request the excel file be created. So no need for an additional save screen.

  5. #5
    Enthiran is offline Member
    Join Date
    Dec 2010
    Posts
    10
    Rep Power
    0

    Default

    Ya... Its unusual but must be done. The user will not be saving the file in the server but in the user system. The thing is i cant open a file dialog from the webapp to choose a location and asking the user to enter a location in a text field will not make 'em happy.

    Any Ideas..??:confused::confused:

  6. #6
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,016
    Rep Power
    20

    Default

    Pardon?
    You mean the user is downloading the file?

    In which case simply stream the file to the user directly rather than saving it on the server.
    Let the browser do its thing and ask the user whether they want to open it or save it.

  7. #7
    Enthiran is offline Member
    Join Date
    Dec 2010
    Posts
    10
    Rep Power
    0

    Default

    Quote Originally Posted by Tolls View Post
    In which case simply stream the file to the user directly rather than saving it on the server.
    Let the browser do its thing and ask the user whether they want to open it or save it.

    And thats what i want to know. How do i do that???
    Last edited by Enthiran; 01-05-2011 at 01:07 PM.

  8. #8
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,016
    Rep Power
    20

    Default

    Right.
    Your class that creates the Workbook should accept an OutputStream which is where the class should write the Workbook. The calling Servlet (not JSP) should pass the HttpResponse output stream to that instance of the class that makes the Workbook.

    That's it.

    Java Code:
    ... sample Servlet code
    excelCreatingClass.makeExcelDocument(response.getOutputStream(), ... any other stuff);
    
    ... sample method for excel creating class
    public void makeExcelDocument(OutputStream out, ... other stuff) {
        workbook = new HSSFWorkbook();  // Assumes workbook is a class attribute
        ... code for making your excel file
        workbook.write(out);
    }
    This all assumes POI, but it's the same idea for other Excel packages.

    ETA: Note, I wouldn't copy that exactly since it's not the best structure IMO. It's just to show you the general flow.

  9. #9
    Enthiran is offline Member
    Join Date
    Dec 2010
    Posts
    10
    Rep Power
    0

    Default

    thanks tolls... Is there a way that i can do that in my .java file only. Like i can't modify anything in the servlets. Tomcat is my app server. I need the browser to download the file thats it.Is there a way.. Anything in apache commons..?? Any API's....

  10. #10
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,016
    Rep Power
    20

    Default

    Nope.
    What's calling this class?
    If it's a JSP then the response to the client has already started so you can't suddenly start sending something else.

    I really don't believe you can't alter the servlets since you control that code by the simple fact you (whether you directly or whoever you are working for) are getting the servlet(s) to call your class. Anything else is political and I don't play that game.

    Since you can't alter servlets (does this include creating new ones?) I would say you're stuffed. Short of sticking the excel file in a folder under your web app and providing a link directly to the file (which is an appalling hack) I'm not sure what else to say.

  11. #11
    Enthiran is offline Member
    Join Date
    Dec 2010
    Posts
    10
    Rep Power
    0

    Default

    Ya k...

    What option do i have if i have to create a new servlet...

  12. #12
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,016
    Rep Power
    20

    Default

    If you can create one then why not change an existing one?

    Well...if you can create one then you don't have to dump the file under the web app directory, but can dump it elsewhere on the server. The Servlet can then read the file and stream it to the client. Note that this is only a slight improvement. You'll still end up with a load of files on your server for no good reason. And there'll be nothing to prevent someone trying to read excel files they didn't create.

Similar Threads

  1. Open/Save dialog in Netbean
    By dauphin in forum NetBeans
    Replies: 0
    Last Post: 12-22-2010, 10:47 AM
  2. scanned image save by swing dialog box
    By gaurav17may in forum AWT / Swing
    Replies: 8
    Last Post: 07-20-2010, 12:48 PM
  3. How to open a SAVE file dialog box without using SWING or AWT
    By SAYAN in forum JavaServer Pages (JSP) and JSTL
    Replies: 2
    Last Post: 02-25-2010, 01:30 AM
  4. save dialog problem
    By masa in forum AWT / Swing
    Replies: 2
    Last Post: 03-06-2009, 12:41 AM
  5. File dialog with save
    By manpreet in forum New To Java
    Replies: 1
    Last Post: 01-02-2009, 05:44 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •