jQuery in Action, 2nd edition*
The moose likes JSF and the fly likes Problem: nothing works in jsp after downloading Excel.    Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Problem: nothing works in jsp after downloading Excel.    " Watch "Problem: nothing works in jsp after downloading Excel.    " New topic
Author

Problem: nothing works in jsp after downloading Excel.

Priyanka mittal
Greenhorn

Joined: Jan 06, 2010
Posts: 1
I have a "search.jsp" with a commandButton to generate excel. "Report.jsp" opens up in a new window when i click on this button by running below mentioned javascript. I can download Excel successfully by clicking on Download Excel link in report,jsp. Problem is, once i close this new window, I am unable to perform any other action in "search.jsp" even if i do not perform download. If i click on any other button or link "search.jsp", it replaces whole jsp with the Downlaod Excel link. and nothing happens after that . i need to close the seesion and start all over again from login page. Does anyone has solution. It will be big help. Thanks.

JAVASCRIPT:

--------------------------------------------------------------------------------
function aaaa()
{
mywindow =window.open('report.jsf', 'popupWindow', 'width=400,height=200,left=0,top=100,screenX=0,screenY=100');
}

Following is report.jsp:

--------------------------------------------------------------------------------
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://www.backbase.com/2007/jsf" prefix="bjsf" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<f:view>
<h:form>
<h:commandLink actionListener="#{searchpage.export}" value="Download Excel" />
<a href="javascript:window.close();return false;">cancel</a>
</h:form>
</f:view>
</body>
</html>

Following is export function which runs when i click on above commandlink "Download Excel":

--------------------------------------------------------------------------------
public void export(ActionEvent event) {
try {
FacesContext context = FacesContext.getCurrentInstance();
HttpServletResponse response = (HttpServletResponse) context
.getExternalContext().getResponse();
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition",
"attachment; filename=report.xls");
ServletOutputStream servletOutputStream = response
.getOutputStream();
WritableWorkbook workbook = Workbook
.createWorkbook(servletOutputStream);
WritableSheet sheet = workbook.createSheet("First Sheet", 0);
WritableFont lfont = new WritableFont(WritableFont.ARIAL, 10);
lfont.setBoldStyle(WritableFont.BOLD);
WritableCellFormat lformat = new WritableCellFormat(lfont);
lformat.setBackground(Colour.DARK_RED2);
lformat.setBorder(Border.ALL, BorderLineStyle.THICK);
WritableFont rfont = new WritableFont(WritableFont.ARIAL, 10);
WritableCellFormat rformat = new WritableCellFormat(rfont);
rformat.setBorder(Border.ALL, BorderLineStyle.THIN);
for (int i = 0; i < this.list.size(); i++) {
HashMap h = (HashMap) this.list.get(i);
if (i == 0) {
Set s = (Set) h.keySet();
Iterator itr = s.iterator();
int j = 1;
while (itr.hasNext()) {
Label label2 = new Label(j, 1, itr.next().toString(),
lformat);
sheet.addCell(label2);
j++;
}
}
Collection c = h.values();
Iterator itr = c.iterator();
int j = 1;
while (itr.hasNext()) {
Label label2 = new Label(j, (i 2), itr.next().toString(),
rformat);
sheet.addCell(label2);
j+;
}
}
workbook.write();
workbook.close();
context.responseComplete();

} catch (Exception e) {
e.printStackTrace();
}
}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem: nothing works in jsp after downloading Excel.
 
Similar Threads
JEXCEL to JSP
Writing a content in excel in incremental way
from where to download org.apache.poi.hssf.usermodel package???????
Printing contents
how to estimate Time to download a file using JSP