Results 1 to 12 of 12
Thread: Save Dialog
- 01-05-2011, 10:21 AM #1
Member
- Join Date
- Dec 2010
- Posts
- 10
- Rep Power
- 0
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.
- 01-05-2011, 10:55 AM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,460
- Rep Power
- 16
What do you mean by "save the excel file"?
- 01-05-2011, 11:07 AM #3
Member
- Join Date
- Dec 2010
- Posts
- 10
- Rep Power
- 0
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.
- 01-05-2011, 11:18 AM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,460
- Rep Power
- 16
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.
- 01-05-2011, 12:12 PM #5
Member
- Join Date
- Dec 2010
- Posts
- 10
- Rep Power
- 0
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:
- 01-05-2011, 12:36 PM #6
Moderator
- Join Date
- Apr 2009
- Posts
- 10,460
- Rep Power
- 16
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.
- 01-05-2011, 12:55 PM #7
Member
- Join Date
- Dec 2010
- Posts
- 10
- Rep Power
- 0
- 01-05-2011, 01:27 PM #8
Moderator
- Join Date
- Apr 2009
- Posts
- 10,460
- Rep Power
- 16
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.
This all assumes POI, but it's the same idea for other Excel packages.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); }
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.
- 01-06-2011, 09:16 AM #9
Member
- Join Date
- Dec 2010
- Posts
- 10
- Rep Power
- 0
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....
- 01-06-2011, 09:22 AM #10
Moderator
- Join Date
- Apr 2009
- Posts
- 10,460
- Rep Power
- 16
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.
- 01-06-2011, 12:32 PM #11
Member
- Join Date
- Dec 2010
- Posts
- 10
- Rep Power
- 0
Ya k...
What option do i have if i have to create a new servlet...
- 01-06-2011, 01:41 PM #12
Moderator
- Join Date
- Apr 2009
- Posts
- 10,460
- Rep Power
- 16
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
-
Open/Save dialog in Netbean
By dauphin in forum NetBeansReplies: 0Last Post: 12-22-2010, 10:47 AM -
scanned image save by swing dialog box
By gaurav17may in forum AWT / SwingReplies: 8Last Post: 07-20-2010, 12:48 PM -
How to open a SAVE file dialog box without using SWING or AWT
By SAYAN in forum JavaServer Pages (JSP) and JSTLReplies: 2Last Post: 02-25-2010, 01:30 AM -
save dialog problem
By masa in forum AWT / SwingReplies: 2Last Post: 03-06-2009, 12:41 AM -
File dialog with save
By manpreet in forum New To JavaReplies: 1Last Post: 01-02-2009, 05:44 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks