开发者

servlet: convert an ServletInputStream into a FileInputStream [duplicate]

This question already has answers here: How can I upload files to a server using JSP/Servlet? (14 answers) Closed 3 years ago.

i'm writing a servlet that receives a xml file, gives it to another class and gives a html file with some comments back to the client. I'm getting the input-xml with something like:

input = request.getInputStream();

but this input is a ServletInputStream and the other class(for the comments) needs a FileInputStream.

If i give the XMLEventReader(in the other class) the ServletInputStream, i get a parsing error:

ParseError at [row,col]:[1,1]
Message: Content is not al开发者_StackOverflow社区lowed in prolog.

And i think this is because of the servletinputstream instead of the fileinputstream.

Greetings i hope somebody is able to help me:)


I think it's unlikely that the latter problem is due to it being a ServletInputStream. The parser shouldn't care about the source of the data.

I think it's rather more likely that the data in the input stream is incorrect.

Your class which currently requires FileInputStream should be refactored to work with InputStream if at all possible... otherwise you'll have to write the data to an actual file first, which is obviously not ideal.


you should read the data from the ServletInputStream, and dump it into a FileOutputStream. this way you can look at the data that is being sent, then test that data separately using FileInputStream with the class you described that needs it. my guess is that the same thing will happen as is happening now since like the previous poster suggested, the data is probably in the wrong format.


Okay, i am now a bit smarter:) The problem is: In the ServletInputStream is at the beginning(and one line at the end) some header information (as content-type, etc..). Is there a smart solution for cutting this information?

greetings

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜