aspose file tools*
The moose likes Servlets and the fly likes Open an XML file in a popup window Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Open an XML file in a popup window" Watch "Open an XML file in a popup window" New topic
Author

Open an XML file in a popup window

amit kumar goyal
Greenhorn

Joined: Dec 07, 2006
Posts: 10
Hello .......

I have a web page where a user clicks on a link to generate xml file. I am generating this xml file inside a servlet and then writing it to the ServletOutputStream. This shows me a dialog box asking me to save or open the file. The save is working fine but when I open the file the xml file is opening in the same window. What I want is to open the file in a new window.

Thanks.
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

OK, You mean when you save a file on a system and then open it, it gets open in "browser" which dosen't support "tabs" ?


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
amit kumar goyal
Greenhorn

Joined: Dec 07, 2006
Posts: 10
There are 3 options in dialog box save,open and cancel. When I select save its working fine, but when I select open in the dialog box it opens the file in the same browser window as my webpage. I want to open this file in a new Window.
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

This is browser issue, One need to check out any property/option in that browser which enable it to open html/xml in new tab/window.

One work around to this,
Put the link on JSP page, ask user to click on this link to get XML, then user clicks to link, it open in a new window (by using target="_blank"), link calls servlet, then user can view/download from that new window
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Use target="_blank" in the link.
amit kumar goyal
Greenhorn

Joined: Dec 07, 2006
Posts: 10
Thankyou everybody for the replies....

I cannot set the target=_blank because it is not a link but its a button to generate the xml. The button submits the request to a servlet which generates the xml. I have set the content type as application/xml and content disposition as attachment for the response headers. But when I open the file from the dialog box it opens the file in the same browser window. I want to open it in a pop up.
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

amit kumar goyal wrote:
The button submits the request to a servlet which generates the XML. I have set the content type as application/xml and content disposition as attachment for the response headers. But when I open the file from the dialog box it opens the file in the same browser window.

This is the expected behavior from any browser, I already suggest one alternative to this. This is a browser behavior and you can't change it.
amit kumar goyal wrote:
I cannot set the target=_blank because it is not a link but its a button to generate the xml.
I want to open it in a pop up.

One solution, "submit" the action/path from JavaScript on "onclick()" event. Submit it by opening a pop window with the specified FORM action as a URL parameter in popup window. I never tried this but give it a try, also, If you modified your servlet to generate XML and return it as a string rather than stream, you won't asked for save/open message box , XML directly get displayed in popup window.

HTH
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
amit kumar goyal wrote:Thankyou everybody for the replies....

I cannot set the target=_blank because it is not a link but its a button to generate the xml. The button submits the request to a servlet which generates the xml. I have set the content type as application/xml and content disposition as attachment for the response headers. But when I open the file from the dialog box it opens the file in the same browser window. I want to open it in a pop up.

You can still use target="_blank" for this. Set it in the <form>.
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Bauke Scholtz wrote:
You can still use target="_blank" for this. Set it in the <form>.

That's indeed a good solution, But as per this link, its use is deprecated, instead open a action URL in new/popup window.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Open an XML file in a popup window