Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

XML File Upload

 
Richard Green
Ranch Hand
Posts: 536
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would like to create a servlet that can handle XML file uploads. The servlet should read the uploaded XML file to create Java objects (using JAXB).

How would I go about doing this? I used the request.getInputStream() function - However, it gives me more than what I wanted.

This is what I get:



I am just interested in the *** xml content ***

So, I guess I need to parse the InputStream to get the xml? Is that how everyone else does file upload processing?

I've read somewhere that Apache Commons FileUpload has lots of utilities that can make upload processing easier. But before I go to my manager to get his approval to use a 3rd party library (Apache), I would like to know if what I want to achieve can be done using servlet APIs alone.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It could be done with the existing API but it's a lot of work.
You would, pretty much, end up doing what the writers of the 3rd party libraries have already done (including learning some things the hard way).

See:
http://faq.javaranch.com/java/FileUpload
[ November 18, 2007: Message edited by: Ben Souther ]
 
Richard Green
Ranch Hand
Posts: 536
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Servlet and JSP specs do not make any special provisions for multipart requests (file uploads).

Servlet and JSP developers either have to depend on third party libraries or make their own framework for this. Fabricating own framework is just like re-inventing the wheel.


I am surprised. Even bloody PHP has built in functions to handle file uploads..

Thanks Ben. I guess I'll have to use Jakarta Commmons.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Having it built in doesn't necessarily make it better.

The Jakarta library is managed by the same foundation as Tomcat so, if this were built into the spec, the folks at Tomcat would probably be using these libraries anyway. And, since so many commercial containers use Apache libraries in their products (Jasper, for instance), it's probably safe to assume that they might also use the same code.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic