This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
I have a jsp page which is showing data in that page from DB.there is also a facility to show data in excel file.So there is a link to import the data in excel file.
I have noted down that url by pointing the cursor to that link that is also in the attached jpg file.Now i am hitting that url using url class but it will showing some jsp code,i think of that page in the ouput of java file.
But i want to save that data in excel file as it is occurring from GUI by clicking that icon.How can i save that file on the system by hitting that url.
I assume you want to just click on the link and have the data showing on your browser page to be saved in an Excel file. Unfortunately, it's not that simple. You must do the following:
1. When the user clicks the link, you need to send a request to the servlet.
2. The servlet gets the data from the database.
3. The servlet converts the data into a format that Excel can understand. This can be for example, true Excel format, comma-delimited or tabbed delimited, data. (For true Excel format see the Apache POI API.)
4. The servlet sends the data back to the browser not as HTML but as the Excel-formatted data. This is done by setting the Content-Type (and other fields) in the HTTP header of the HttpServletResponse 5. The browser will then receive the data and, depending on its settings, will display the data in Excel or offer to save the file, or something else.
I hope there are enough buzzwords in the above to start your google investigation.
berender mavi
Greenhorn
Joined: Feb 18, 2011
Posts: 29
posted
0
buddy actually my front end is doing the whole work to export data to excel file.but i want a write a java program that runs in background and automatically click on that link and save the excel.
there is no problem in my jsp page but i want to do it also from my java code so that automatically at a particular time excel file is downloaded on the system so no need to click on the link manually.
Are you asking how to generate the Excel file, or how to make the browser save the file without user interaction?
If you're asking for the later, for security reasons most browsers won't allow this. At best, you could have a "refresh" meta tag point to the generated Excel file. The user would likely be prompted to save the Excel file after the refresh timeout (unless they've sent their browser to automatically save that file type).
OCPJP
In preparing for battle I have always found that plans are useless, but planning is indispensable. -- Dwight D. Eisenhower
Krysthiam Diaz
Greenhorn
Joined: Aug 16, 2011
Posts: 1
posted
0
I assume you want to just click on the link and have the data showing on your browser page to be saved in an Excel file. Unfortunately, it's not that simple. You must do the following:
1. When the user clicks the link, you need to send a request to the servlet.
2. The servlet gets the data from the database.
3. The servlet converts the data into a format that Excel can understand. This can be for example, true Excel format, comma-delimited or tabbed delimited, data. (For true Excel format see the Apache POI API.)
4. The servlet sends the data back to the browser not as HTML but as the Excel-formatted data. This is done by setting the Content-Type (and other fields) in the HTTP header of the HttpServletResponse 5. The browser will then receive the data and, depending on its settings, will display the data in Excel or offer to save the file, or something else.
I hope there are enough buzzwords in the above to start your google investigation.
Tom Reilly, what about if I'm using spring MVC? Is there any problem related to the spring context if I use a servlet to create my Excel file?