Solved

How can I debug a download from a jsp.

Posted on 2011-02-14
7
434 Views
Last Modified: 2012-05-11
Hi All,

I have a problem with my jsp. For some reason the download mechanism has broken and I can't find any tools that will help me track the problem. It has not been tested recently so I can't track down the code change that caused it to break.

if (params.packed) {
        // Save Report stuff
        String fileExtension = ".html";
        if (params.xls) {
          response.setContentType("application/plain");
          fileExtension = ".xls";
        }
        final String fileMid;
        if (params.automatic) {
          fileMid = "." + DateFormatter.toSavedReportsDatetime(params.now);
        }
        else {
          fileMid = "_" + DateFormatter.toFilenameYYYY_MM_DD_HH_MM_SS(params.now);
        }
        Log.logln("setHeader: attachment; filename=\"" + reportName + fileMid + fileExtension+"\"");
        response.setHeader("Content-Disposition", "attachment; filename=\"" + reportName + fileMid + fileExtension+"\"");
        Log.logln("setHeader: done");
      }

Open in new window


The attached code is the critical bit. params.packed will be set if a download is requested, params.xls requests xls format. This all should (I believe) work but it doesn't. No file dialog pops up, it just redisplays the report.

Is there a trick in FireBug I can use to inspect the "Content-Disposition" or something?

Paul
0
Comment
Question by:PaulCaswell
  • 4
  • 2
7 Comments
 
LVL 40

Expert Comment

by:gurvinder372
ID: 34889547
0
 
LVL 16

Author Comment

by:PaulCaswell
ID: 34889740
RE: jguru link:

I have tried contentType of "application/vnd.ms-excel" and it still does not work. "application/plain" has worked in the past.

RE: devx link:

Sorry - site is broken for me. What does it suggest?

RE: Q_22152089

I am not using HSSF so that suggestion is not my issue - however, I did add:

response.setHeader("Cache-Control", "public");
response.setHeader("Pragma", "public");
response.setHeader("Expires", "0");            

and changed:

response.setHeader("Content-Disposition",...

to

response.setHeader("Content-disposition",...

and that does not solve the problem.

Paul
0
 
LVL 40

Expert Comment

by:gurvinder372
ID: 34889763
you can use firebug to check the response headers
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
LVL 16

Author Comment

by:PaulCaswell
ID: 34890522
I'm not at work at the moment so I can't check but my thoughts were that this should be a server-side issue shouldn't it?

If the Content-Disposition is acted on at the client side then certainly I can check the Response headers. What should I look for?

NB: The jsp is a target of a forward (as opposed to a redirect). Could that be my issue?

Paul
0
 
LVL 16

Accepted Solution

by:
PaulCaswell earned 0 total points
ID: 34895541
It seems I have managed to fix the issue.

The problem was that there was too much data being sent to the client before the Content-Disposition was changed.

It turns out that the content disposition must be changed before a certain buffer size is exceeded on the server. Not sure of the size of the buffer but I was sending more than 8k before the change.

I now change the content disposition within 1/2 k of the start of the data stream and all works fine.

Paul
0
 
LVL 27

Expert Comment

by:rrz
ID: 34899283
0
 
LVL 16

Author Closing Comment

by:PaulCaswell
ID: 34936294
I found the answer.
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
This article discusses how to create an extensible mechanism for linked drop downs.
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

776 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