Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Excel file opening problem

 
Ranch Hand
Posts: 415
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I am trying to open an excel file by clicking a link where it goes to action class and then sets the content type to excel and I am opning it from there´┐Żbut the strange thing is that a file download opens with open/save/cancel but in the same window but it is showing a warning in the dailog box(windows warning which comes as an exclamatory mark) saying "This type of file could harm your computer if it conatins malicious code" and on cliking open it shows a dialog saying "Could not open http://localhost:8080/context/myaction.do?fileName=3.xls" .Dont know why its trying to opne my action url rather than it should look for 3.xls in my folder

Any clue on this would be helpful
 
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might need to have the action do a redirect to the file.
 
sreenath reddy
Ranch Hand
Posts: 415
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yah marc

I am opening it by redirecting to that url ths is my code which i am using to opnen that file in an action class

String format = request.getParameter(WebConstants.FORMAT);
String reportId = request.getParameter(WebConstants.REPORT_ID);
HttpSession session = request.getSession();
String sFilePath = WebConstants.REPORT_PATH + reportId
+ ReportUtil.getFormatExtn(format);
if (format.equals(WebConstants.EXCEL)) {

response.setContentType("application/vnd.ms-excel");


}

// This is to enable him to go to the listing page of reports
request.setAttribute(CommandConstants.CmdID, CommandConstants.LIST_RPT);

return new ActionForward(sFilePath,false);
 
Marc Peabody
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shouldn't it be:
return new ActionForward(sFilePath,true);
for a redirect?
 
sreenath reddy
Ranch Hand
Posts: 415
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi marc

If i make that true ,then request and response will be lost which results the excel file being opened as junk ....so i need to set the contenttype header to excel .so i need to persist the response attributes hence false is used
 
Switching from electric heat to a rocket mass heater reduces your carbon footprint as much as parking 7 cars. Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic