• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Download excel file

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using JSF, Java 1.6 , tomcat. I generated excel file and save it in local d drive. I want to download the excel file in browser . Below is the sample code

piece of code


}

In jsf/JSP page



I googled and use the same, Don;t know where I am wrong . Please help, struck with this simple one for two days
 
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does it show any error?
 
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First, not sure why you are saving the file on the server.
I would drop that code entirely, at least then you can focus on the response part.

I'm fairly sure that you don't have to close the output stream for the response.  The framework handles all of that.

As Swastik asks, though, do you get any errors?  What do you see happening on the browser, using the dev tools (F12) to see what the request/response is.
 
Saloon Keeper
Posts: 26294
186
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dave Tolls wrote:First, not sure why you are saving the file on the server.



Probably because it was easier to construct the content as a temporary file and then copy the file contents to the output stream.

Dave Tolls wrote:I'm fairly sure that you don't have to close the output stream for the response.  The framework handles all of that.



Probably. I recall possibly having trouble long ago actually if I did close the stream myself. Or maybe if I didn't. It's time to consult the documentation on that.

Dave Tolls wrote:As Swastik asks, though, do you get any errors?  What do you see happening on the browser, using the dev tools (F12) to see what the request/response is.



Upvoted. Also check catalina.out and the tomcat localhost logfiles.
 
Dave Tolls
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Holloway wrote:

Dave Tolls wrote:First, not sure why you are saving the file on the server.



Probably because it was easier to construct the content as a temporary file and then copy the file contents to the output stream.



It's an Apache POI Workbook.
There's no need to do anything other than stream it directly to the client.
I don't think I've ever stored a POI generated Excel "file" to disk in a webapp other than for testing purposes.
 
dpriya pratheep
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry for late reply. Thanks you friends.

@Swastik Dey

It is not showing any error. It is not downloading in the web browser.


@Dave Tolls


I don't want to save the file in server . Just for check the excel generated part is working or not , I generate and save locally. Actually I want to download the file at client browser..

My doubt is

 
this line is ok ? I am new to this JSF and how it is handling request and response . Here we are using spring bean to pass to and fro from client to server . To send response back I use above line ? Is ti correct way ?



 
Tim Holloway
Saloon Keeper
Posts: 26294
186
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh wait. JSF.

You don't want JSF to handle the Excel stuff. JSF is designed to work with HTML forms and fixed displays. JSF puts its own headers into the response stream and it has a different lifecycle than JSPs do.

What you want is a plain old servlet. That way you have total control over what gets output and when. JSF doesn't mind sharing a webapp with servlets and JSPs, so that's no problem.
 
Pay attention! Tiny ad!
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic