Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Rui Yuan
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 20902
76
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic