1

I wanted to know if there is a way in which I can pass an HTML table from my JSP page using the Java request object.

More precisely, this is what my table looks like..

table id="tableid"
thead
tr
th...column1 header.../td
th...column2 header.../td
/tr
/thead

tbody
tr
td...column1 data../td
td..column2 data../td
/tr
/tbody

/table

I've a method in my Java code getExcelVersion(), for which I wanted to pass the above table as an argument.

I actually wanted to pass data from the table(column1 data, column2 data) as an List, ArrayList or anything data type, and not the actual HTML. What I'm basically trying to achieve is something as follows:

I've an HTML table, that I need to export to excel on a button click. For this purpose, I'm using libraries from Apache-POI, and the foll. code block.

HSSFWorkbook workbook = getExcelVersion(); resp.setContentType("application/vnd.ms-excel"); resp.setHeader("Content-Disposition", "attachment; filename=\"contacts.xls\""); workbook.write(resp.getOutputStream()); resp.flushBuffer();

Now, I wanted to know how would I pass table data(column1 data, column2 data) to my getExcelVersion() method.

Thanks,
Pritish.

Pritish
  • 769
  • 4
  • 13
  • 28
  • What exactly do you want to pass to your method? From your example it's as if you want to pass back the HTML code is this correct? – Jaime Garcia Jul 15 '10 at 17:26
  • This question makes honestly said no sense. I think you confused some terms and/or are looking in the wrong direction for the solution. I think it's better to take a step back and elaborate the actual functional requirement in detail for which you though that *this* is the "right" solution (but which actually isn't at all). – BalusC Jul 15 '10 at 17:41

1 Answers1

1

Apache POI doesn't take a HTML table as input, but just fullworthy Java objects. Just reload the same data in the servlet as you loaded for the initial display in JSP and then feed it to Apache POI instead of forwarding to JSP. If you want to avoid reloading the same data, then you can consider to store it in the session scope, but this has a negative impact on server memory usage and client experience.

At least, I'm assuming that your JSP/Servlet/database code is well written, else it's going to be a lot of refactoring/rewriting work.

Related questions:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555