views:

111

answers:

2

I can't seem to solve this.

Originally the JSP code had a function in Javascript that would call a jsp from another server:

window.open("<%= otherServer %>/ourreports/Company/fooreport.jsp?index"+index,"Foo",options);

where otherServer was a local server (http://192.168.4.40:8080) This worked fine, and would pop out a new window with fooreport.jsp.

The task now is to point to a jsp in the same server. So, I changed it to

window.open("/reports/Company/fooreport.jsp?index"+index,"Foo", options);

And I would get a download the file popup instead of a page

I also tried to do all of the following:

window.location = "/reports/Company/fooreport.jsp?index="+index;
window.location.href = "/reports/Company/fooreport.jsp?index="+index;
window.location = "http://localhost:9080/reports/Company/fooreport.jsp?index="+index;
window.location.href = "http://localhost:9080/reports/Company/fooreport.jsp?index="+index;

And I still get the popup to download the fooreport.jsp to my computer.

The jsp is well-formed, has the DOCTYPE, the tags, the <%@ page declarations... It's essentially the same jsp that was being called before

I'm using WebSphere 7.5.4 and java is 1.5

A: 

window.location should work if the Content-Disposition header of the response is been set to Attachment.

response.setHeader("Content-Disposition", "attachment; filename=yourfile.ext");

Noted should be that doing this inside a JSP is a bad idea. If the response concerns binary data, JSP may possibly corrupt it. Do this job in a Servlet. JSP is meant to write template text in, not to write Java code in.

BalusC
Yeah, I know... unfortunately I'm updating 4 year old code, where the Servlet just calls the JSP... and you guessed it... all the code is there in <% %> tags. The final response is a JSP that loads a Crystal Report .rpt
elcool
As long as it is textbased, it may not necessarily malform the data, no. But did setting the content disposition work for you?
BalusC
A: 

The problem resided in the JSP. Calls using window.location and window.open worked fine for other JSPs.

The problem was in the "<% page" declarations. I deleted them, so don't remember exactly, but it had to do with Content-Type and ISO setting. I took them all out, left only the "<% page import" declarations, and now it works correctly.

elcool