同时使用 GET 和 POST
如您所见,我是 jsp/ajax 新手。
在jsp/ajax文件上传网页中,使用POST来上传文件,使用GET来获取上传进度(使用ajax)。
在 doPost() 中文件上传(应该是在服务器端“下载”?)完成并设置进度监听器。
在 doGet() 响应中写入 XML(ajax HttpRequest 是 GET)。
在 doPost() 中响应中写入的 HTML 标记不会显示在浏览器中。重定向在 doPost() 中也不起作用。
我无法在 doGet() 中执行上述任何操作,因为它在 ajax 中被多次调用。不是吗?
如果我想在不同的页面(比如文本文件)显示上传文件的内容,我该怎么办? (我的意思是应该在哪个方法中进行重定向?)
我目前正在做的是在 ajax 中,如果进度为 100%,则使用 window.open() 打开显示文件内容的页面 谁能解释一下正在发生的过程(顺序)。
实际上这是我遵循的代码
ajax文件上传进度
I'm new to jsp/ajax as you can see.
In a jsp/ajax file uploading webpage ,POST is used to upload the file and GET is used to get the uploading progress(with ajax).
In doPost() file uploading(it should be "downloading" in server side?)is done and progress listener is set.
In doGet() response XML is wriitten(ajax HttpRequest is GET).
HTML tags written in response in doPost() is not shown in the browser.Redirection is also not working in doPost().
I can't do any of above in the doGet() since it'is called several times in ajax .isn't it?
If I want to show the content of the uploaded file in a different page(say a text file) how should I do? ( I mean in which method should be the redirection happen?)
What I'm currently doing is in ajax if the progress is 100% ,open the page which shows the content of the file using window.open()
Can anyone please explain the process going on(the sequence).
actually this is the code I followed is
ajax file uploading progress
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许您需要先刷新响应缓冲区?然而,这与重定向不起作用的说法相冲突。也许您的意思是只显示少数 HTML 标签而不是全部?
如果您写入并刷新 HTML 标记,这确实会失败,并在服务器日志中显示
IllegalStateException: response already commit
(您读过它们吗?)提前回复。在调用<之前不要在响应中写入任何内容
doPost()
中的 code>response.sendRedirect()。让 ajax 和doGet()
来处理您之前讨论的那些“HTML 标记”。在相关说明中,您可能会发现这个答案也很有趣: HTML5 File上传到Java Servlet。
Perhaps you need to flush the response buffer first? This however conflicts with the statement that redirection doesn't work. Perhaps you mean that only a few HTML tags are shown and not all?
This will indeed fail with
IllegalStateException: response already committed
in server logs (did you read them?) if you write and flush HTML tags to the response beforehand.Do not write anything to the response before calling
response.sendRedirect()
indoPost()
. Let ajax anddoGet()
worry about handling those "HTML tags" you're talking about before.On a related note, you may find this answer interesting as well: HTML5 File Upload to Java Servlet.