View Full Version : Excel View Error With Internet Explorer
tobysaville
Apr 27th, 2006, 11:03 AM
Im posting this incase others come across the same problem, cause it plagued me for weeks.
One of my controllers returns an implementation of a AbstractExcelView. In order to give the user the option to save or download the spreadsheet, i set the following response header:
response.setHeader("Content-Disposition", "attachment; filename=sheet.xls");
I then set caching to 0 (in the constructor) with
setCacheSeconds(0);
Now whenever i requested this Excel controller, a dialog would appear asking if i would like to save or open the result. If i clicked save and then viewed the file that was saved to my hard drive, i saw that it was generated correctly (so far all good).
However if i clicked the Open button on the previous dialog, i would get an error message stating:
C:\Temp\Temporary Internet Files\Content.IE5\S1244HKJD\sheet[1].xls chould not be found. check the spelling of the file name and verify that the file location is correct.
Oh yeah, and it worked fine in mozilla. And it happened on other peoples computers.
After two weeks of sobbing in the corner i realised that it was the dirty filthy cacheSeconds setting. If this was set to any other value (-1 included, and yes i understand the difference between 0 & -1) then the document would open correctly from the open dialogue.
In summary, dont use the above settings together. they suxors.
- tobes
thevictor
Jun 14th, 2006, 10:32 AM
Thanks tobes,
That hint was really helpful. In my case, the didn't had the cacheSeconds setting and it was working in a regular app server instance. But, when we moved to an environment with Web, app server with cluster and virtual servers, we started seeing similar errors on both open & save in IE (was ok in Firefox). After setting this cache to a min, it works fine now.
thank you,
-Vijay
heymjo
Sep 5th, 2006, 10:06 AM
very helpful tip, i spend a good few hours debugging this myself until i came here for more clues.
Satya Karanam
Dec 7th, 2006, 05:26 AM
Hi all, i have a similar problem. Iam using internet explorer 6.0.
When iam building a excel document Iam specifying a user defined name for the excel document in the response.setHeader and Iam setting the cacheseconds to 1 in the controller with the help of setCacheSeconds(1) statement.
But the problem here is when I click an execute button from the UI then one dialog box appears with three buttons - Open, Save and Cancel. If I click Save button then the excel doc will be saved under the specified location. Every thing is fine uptill here.
But if I click the open button for the first time then one dialog box appears with a mesage saying that c:\Documents and settings\sr185024\Local settings\Temporary Internet Files\content.IE5\YNR602SX\TicketLog2006-12-01_2006-12-06[2].xls could not be found. Check the spelling of the file name, and verify that the file location is correct. The consecitive clicks to open button, opens the excel file. It does not open the file and gives the above mentioned error only for the first click.
My code is:
protected void buildExcelDocument(Map model, HSSFWorkbook workbook,
HttpServletRequest request, HttpServletResponse response) {
String excelFileName = "TicketLog" + request.getParameter("fromDate")
+ "_" + request.getParameter("toDate") + ".xls";
logger.info("File name is " + excelFileName);
response.setHeader("Content-Disposition", "attachment; filename=" + excelFileName);
<some logic here>
loadArchiveList(sheet, archiveLogList); }
Please help me on this.
tobysaville
Dec 7th, 2006, 05:46 AM
try setting cacheSeconds to -1, meaning no cache headers created.
also check that the cacheSeconds isnt set in two places like in your controller definition in the app context and in the constructor
Satya Karanam
Dec 7th, 2006, 07:12 AM
Thanks for the quick response.
I have tried setting the cache seconds to -1 also. But still the behaviour is same as mentioned earlier in my post. And Iam setting the cache seconds only in one places that is exportTicketsToCSVFile method. Is there any other place I need make changes?
Please find my controller code:
public class SmTicketLogAdminController extends SimpleFormController {
/**
* Reference to SmTicketDaoIf
*/
protected SmTicketDaoIf smTicketDao;
/**
* List to hold archive data.
*/
protected List archiveList = null;
/**
* String holding cancel request paramter.
*/
protected static final String PARAM_CANCEL = "_cancel";
/**
* This method returns <code>SmTicketDaoIf<code> instance.
*
* @return SmTicketDaoIf
*/
public SmTicketDaoIf getSmTicketDao() {
return smTicketDao;
}
/**
* This method set the <code>SmTicketDaoIf<code> instance.
*
* @param smTicketDao
*/
public void setSmTicketDao(SmTicketDaoIf smTicketDao) {
this.smTicketDao = smTicketDao;
}
/**
* This method exports the tickets to CSV file.
*
* @param command
*/
protected void exportTickets(Object command) {
logger.info("Entered into exportTickets...");
SmTicketLogAdminForm ticketLogAdminForm = (SmTicketLogAdminForm) command;
if (ticketLogAdminForm != null) {
try {
exportTicketsToCSVFile(ticketLogAdminForm);
} catch (Exception exception) {
logger.info("Exception is" + exception.getMessage());
}
} else {
throw new NullPointerException("Command is empty.");
} }
/**
* Overridden method to handle form submition.
*/
public ModelAndView onSubmit(Object command, BindException errors)
throws ServletException {
logger.info("Entered into onSubmit method...");
Map<String, List> model = new HashMap<String, List>();
if ((getArchiveList() != null) && (getArchiveList().size() > 0)) {
model.put(SmTicketLogExcelView.LIST_KEY, getArchiveList());
}
return new ModelAndView(new SmTicketLogExcelView(), model); }
/**
* Overridden method to handle form cancel action
*/
protected ModelAndView processFormSubmission(HttpServletRequest request,
HttpServletResponse response, Object command, BindException errors)
throws Exception {
logger.info("Entered into processFormSubmission method...");
if (WebUtils.hasSubmitParameter(request, PARAM_CANCEL))
return new ModelAndView(new RedirectView("index.htm"));
return super.processFormSubmission(request, response, command, errors); }
/**
* This method exports the database entries to a CSV file and sets the size
* of the Archived List with the number of records that are exported.
*
* @param ticketLogAdminForm
* @throws Exception
*/
protected void exportTicketsToCSVFile(
SmTicketLogAdminForm ticketLogAdminForm) throws Exception {
logger.info("Entered into exportTicketsToCSVFile...");
try {
setCacheSeconds(-1);
setArchiveList(getSmTicketDao().exportTicketsToCsv File(
getFromDate(ticketLogAdminForm), getToDate(ticketLogAdminForm),
isDeleteArchiveChecked(ticketLogAdminForm)));
} catch (Exception exception) {
logger.info("Exception caught is " + exception.getMessage());
} }
/**
* This method converts the String values to Date.
*
* @param request
* @param binder
*/
protected void initBinder(HttpServletRequest request,
ServletRequestDataBinder binder) {
logger.info("Inside initBinder");
// convert to java.util.Date
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
dateFormat.setLenient(false);
binder.registerCustomEditor(Date.class, null, new CustomDateEditor(
dateFormat, true));
}}
tobysaville
Dec 7th, 2006, 07:36 AM
cacheSeconds needs to be set in the constructor, not in a method call
Satya Karanam
Dec 8th, 2006, 12:17 AM
Thank you so much,
it worked fine after setting the cache seconds to -1 in the constructor of my controller.
falseneutral
Jul 30th, 2007, 06:40 AM
another thank you for this solution. great post.
vBulletin® v3.7.3, Copyright ©2000-2008, Jelsoft Enterprises Ltd.