开发者

window.location and window.open problem

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 chang开发者_开发技巧ed 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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜