Solved

How can I debug a download from a jsp.

Posted on 2011-02-14
7
438 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
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…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

622 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