Frage

Ich habe eine JSP-Seite, dass der Bedarf einige Informationen in eine Form zu akzeptieren, gesagt hat, Form mit einer extra auf die gleiche Seite einreichen „Danke für ______“ div, die erst nach dem Formular platziert wird (unter Verwendung einer Parameterprüfung).

Ich brauche aber auch eine Datei auf dem Server zum Download bereit zu dienen, aber ich kann nicht Verwirrung mit der Content-Disposition Header der Datei zu dienen, da die ganze jsp Seite noch Anzeige benötigt. Wie kann ich biete diese Datei, ohne die Form zu einer anderen Seite einreichen? Was Javascript Trick kann ich verwenden, um ein neues Fenster zu öffnen, die dies tun würden? Javascript wäre in Ordnung, aber nichts, dass ein Popup-Blocker würde Trumpf ..

Ich kann keine a href verwenden, um die Datei zu senden -. Es automatisch getan werden muss,

Auch wenn die Datei (das ist ein pdf) in dem neuen Fenster geöffnet, das ist auch in Ordnung.

War es hilfreich?

Lösung

I have done this before. Load your JSP page as normal, but include a line of Javascript that redirects to another page responsible for serving up the file...

location.href = 'serveFile.jsp';

As long as serveFile.jsp sets the content-disposition header properly, it will simply display the save dialog and won't actually change pages.

How can I offer this file without going to a different page?

You technically can't, but you can remain on the previous page (interface wise) using this method, which achieves a seamless effect I believe you are looking for.

Note: In my implementation of this method, I discovered that after saving the file, navigating to a different page, then hitting the back button, you will get the save dialog again. No way around this.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top