This week's book giveaway is in the Java in General forum.
We're giving away four copies of Helidon Revealed: A Practical Guide to Oracle’s Microservices Framework and have Michael Redlich on-line!
See this thread for details.
  • 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
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

How to Export web page(jsp page) to excel using jsp or servlets

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I am trying to export web page(jsp page ) to excel using jsp or servlets. I am retrieving records from database and displaying in the jsp page, In this page I have a save as excel button, when I click this button I need these displayed records to excel file. I tried with vbscript and javascript but am getting some errors. Please can anyone tell me how to do this using java or jsp or servlets??

Thanks in advance,
Lissy.
 
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would write a servlet that emits a format that Excel understand. The link can hit that servlet.
 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI
you can go head with display tag

/http://www.displaytag.org/1.2/

this link might be useful. export to excel
 
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bear, you are displaying the result in JSP page. It means that you are already records available in request/ session. Now on click on save button why not you call one servlet that servlet will do writing in excel file. After that you can give link to user to download that excel file.

Regards,
Sunil
 
Bear Bibeault
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

xsunil kumar wrote:Bear, you are displaying the result in JSP page. It means that you are already records available in request/ session.


No. The request is long gone by the time the page is displayed in the browser, and no data is automatically stored in the session.

The best solution is to have a servlet that reads the same data and formats it, not as HTML, but as a format that Excel understands.

 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:The best solution is to have a servlet that reads the same data and formats it, not as HTML, but as a format that Excel understands.


I'd say that's debatable; storing the data in the session can work well. That's what the DisplayTag library suggested previously does, which is indeed worth a look if the data is both to be displayed as HTML and downloaded as XLS.
 
Bear Bibeault
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I did not mean to not store in the session -- just that it won't be there automatically. And trying to extract the data from the HTML page after it has been rendered is like trying to get a steak out of hamburger.

Caching the data in the session may be a viable path depending upon the expected usage patterns of the application
 
lisy jessica
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to do this using javascript, but still its not working, here is my code

masterlist_fetch.jsp



This gives me an error in the webpage when i click save as excel button, the error is detailsTable is undefined, Please can anyone help me, I am stuck here.

Thanks in advance.
Lissy.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Apparently you think that because you have an element with name "detailsTable" on your page (two elements, actually, which is a bad idea), that element would be defined as a JavaScript variable. Not so. Read up on the JavaScript methods getElementsByName and getElementById to learn about how to structure your HTML pages so that what you're trying to do becomes possible.
 
lisy jessica
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply, Will try this.
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic