0

我有一个要求,我必须通过 http 请求将 xml 文件发送到 jsp 页面。在服务器端,我已经开发了从请求对象获取 inputStream 并存储到文件中的代码。稍后我正在处理 xml 文件以将数据存储在数据库中。

现在我需要向 jsp 发送一个 xml 文件。那么如何将 xml 文件从 jsp/servlet 发送到服务器...

提前致谢...

4

1 回答 1

0

如果 Xml 文件很小,则可以 store the contents of the xml as String as a request attribute

否则你可以刷新文件作为响应

response.setContentType("text/xml");
PrintWriter out = response.getWriter();
FileInputStream in = new FileInputStream(sample_file);
byte[] buffer = new byte[4096];
int length;
while ((length = in.read(buffer)) > 0){
    out.write(buffer, 0, length);
}
in.close();
out.flush();
于 2013-02-10T14:13:15.980 回答