servlet:将 ServletInputStream 转换为 FileInputStream
我正在编写一个 servlet,它接收 xml 文件,将其提供给另一个类,并将带有一些注释的 html 文件返回给客户端。 我得到的 input-xml 类似于:
input = request.getInputStream();
但此输入是 ServletInputStream,另一个类(用于注释)需要 FileInputStream。
如果我向 XMLEventReader(在另一个类中)提供 ServletInputStream,我会收到解析错误:
ParseError at [row,col]:[1,1]
Message: Content is not allowed in prolog.
我认为这是因为 servletinputstream 而不是 fileinputstream。
问候 我希望有人能够帮助我:)
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 allowed in prolog.
And i think this is because of the servletinputstream instead of the fileinputstream.
Greetings
i hope somebody is able to help me:)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

发布评论
评论(3)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
我认为后一个问题不太可能是由于它是 ServletInputStream 所致。解析器不应该关心数据的来源。
我认为输入流中的数据更有可能不正确。
如果可能的话,当前需要
FileInputStream
的类应该重构为与InputStream
一起使用...否则您将不得不编写数据首先到一个实际的文件,这显然不理想。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 withInputStream
if at all possible... otherwise you'll have to write the data to an actual file first, which is obviously not ideal.