aspose file tools*
The moose likes Sockets and Internet Protocols and the fly likes How can I access an attachment downloaded from a URL in a servlet? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "How can I access an attachment downloaded from a URL in a servlet?" Watch "How can I access an attachment downloaded from a URL in a servlet?" New topic
Author

How can I access an attachment downloaded from a URL in a servlet?

Rui Yuan
Greenhorn

Joined: May 05, 2014
Posts: 5
When I call in a servlet a

URLConnection urlConnection = someURL.openConnection();
The response is an XML file attachment, with Content-Disposition: attachment´╝Ť filename=xxxx Content-Type:XML

Now I would like to parse the XML file, I've tried BufferedReader bf = new BufferedReader(new InputStreamReaderurlConnection .getInputStream())), but bf is null.

If I try to directly open the link in a web browser,the response body is also empty. There will be a dialog box, I can view the xml file if I open the file or save it.

Does anyone have ideas?

Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18843
    
  40

Rui Yuan wrote:
Now I would like to parse the XML file, I've tried BufferedReader bf = new BufferedReader(new InputStreamReaderurlConnection .getInputStream())), but bf is null.


First of all, what is the "InputStreamReaderurlConnection" class you are using? Second, this line won't compile. Can you show us the exact code?

And finally, the only way for the bf variable to be null, is for an exception to be thrown. Can you catch it, print it out, and tell us what it is?

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How can I access an attachment downloaded from a URL in a servlet?