[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

JSP export to Excel

Posted on 2009-05-05
2
Medium Priority
?
475 Views
Last Modified: 2012-08-14
I have a JSP where I get data from database and display as a report but now I added a href to have  a view in excel .  I have added set content type and set header but no luck - excel file is not opening.

 Below is my code .  

Please help




<table width="98%" border="1" cellspacing="0" align="center">
    <tr align="center">
     <FONT color="#333399" size="4"><STRONG>Summary Report</STRONG></FONT>
	  </tr>
   </table>	
  <div id="blankout">
   <p></p>
 
 
  <center>
 
 
<a type="application/vnd.ms-excel" href="ref_rev_sum_rpt.jsp?msexcel=ref_rev_sum_rpt.xls">
	View in MS Excel </a>  
 <%
 String type=request.getParameter("msexcel");
 
if(type!=null && type.equalsIgnoreCase("msexcel")){
response.setHeader("Content-Disposition", "attachment;filename=ref_rev_sum_rpt.xls");
response.setContentType("application/msexcel");
}
%>
 
 
 
</center>

Open in new window

0
Comment
Question by:Nikki1
2 Comments
 
LVL 2

Accepted Solution

by:
irf44z earned 1500 total points
ID: 24310058
1. Looks like there is a bug in your code: if(type!=null && type.equalsIgnoreCase("msexcel")){
     I think, the variable "type" holds the file name and not the constant "msexcel".
     Probably, you need to change it to:
         if (type != null && type.trim().length() > 0) {

2. The Content Type for EXCEL should be "application/vnd.ms-excel"

3. Also, place the scriptlet at the top of the JSP file (May not be mandatory, but just in case)
<%
  String type=request.getParameter("msexcel");
  if (type != null && type.trim().length() > 0) {
    response.setHeader("Content-Disposition", "attachment;filename=ref_rev_sum_rpt.xls");
    response.setContentType("application/vnd.ms-excel");
  }
%>
0
 

Author Closing Comment

by:Nikki1
ID: 31578092
It worked fine with the small tweak in if statement . Thank you
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Thoughout my experience working on eCommerce web applications I have seen applications succumbing to increased user demand and throughput. With increased loads the response times started to spike, which leads to user frustration and lost sales. I ha…
Introduction A frequently used term in Object-Oriented design is "SOLID" which is a mnemonic acronym that covers five principles of OO design.  These principles do not stand alone; there is interplay among them.  And they are not laws, merely princ…
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to selectively show certain fields based on user input using rules to gather relevant information and data from your forms. The rules feature provides you with an opportunity…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Suggested Courses
Course of the Month18 days, 20 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question