同时使用 GET 和 POST

发布于 2024-12-04 20:12:08 字数 592 浏览 0 评论 0原文

如您所见,我是 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

﹎☆浅夏丿初晴 2024-12-11 20:12:08

在 doPost() 中响应中写入的 HTML 标签未显示在浏览器中

也许您需要先刷新响应缓冲区?然而,这与重定向不起作用的说法相冲突。也许您的意思是只显示少数 HTML 标签而不是全部?


重定向在 doPost() 中也不起作用

如果您写入并刷新 HTML 标记,这确实会失败,并在服务器日志中显示 IllegalStateException: response already commit (您读过它们吗?)提前回复。


如果我想在不同的页面(比如文本文件)显示上传文件的内容,我该怎么办?

在调用<之前不要在响应中写入任何内容doPost() 中的 code>response.sendRedirect()。让 ajax 和 doGet() 来处理您之前讨论的那些“HTML 标记”。

在相关说明中,您可能会发现这个答案也很有趣: HTML5 File上传到Java Servlet

HTML tags written in response in doPost() is not shown in the browser

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?


Redirection is also not working in doPost()

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.


If I want to show the content of the uploaded file in a different page(say a text file) how should I do?

Do not write anything to the response before calling response.sendRedirect() in doPost(). Let ajax and doGet() 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文