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

XML File Upload

Richard Green
Ranch Hand

Joined: Aug 25, 2005
Posts: 536
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.


MCSD, SCJP, SCWCD, SCBCD, SCJD (in progress - URLybird 1.2.1)
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

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 ]

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Richard Green
Ranch Hand

Joined: Aug 25, 2005
Posts: 536
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

Joined: Dec 11, 2004
Posts: 13410

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.
 
 
subject: XML File Upload