Solved

How can I debug a download from a jsp.

Posted on 2011-02-14
7
432 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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Setting Up a Responsive Form 24 41
Website Home page blank 4 27
Urgent need help ASAP With CSS 5 24
SVG Logo 4 20
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…
This article discusses four methods for overlaying images in a container on a web page
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)

746 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now