Solved

How can I debug a download from a jsp.

Posted on 2011-02-14
7
436 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying 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

Showing your events from Google Calendar in Google Maps Why? I travel all week and I thought it would be ideal if staff in office knew where I was based on my calendar. (OK real reason: my son wanted to see where I would be working, and I thoug…
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…

830 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