同时使用GET和POST [英] Using both GET and POST

查看:344
本文介绍了同时使用GET和POST的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如您所见,我是jsp/ajax的新手.
在jsp/ajax文件上传网页中,POST用于上传文件,而GET用于获取上传进度(使用ajax).

在doPost()中完成文件上传(应该在服务器端进行下载"吗?)并设置了进度侦听器.

在doGet()中,响应XML为wriitten(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

推荐答案

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

也许您需要先刷新响应缓冲区?但是,这与重定向不起作用的陈述相冲突.也许您的意思是只显示了几个HTML标记,而不是全部?

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?

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

如果您事先将HTML标记写入并刷新到响应中,则确实会失败,并在服务器日志中显示IllegalStateException: response already committed(您读过它们吗?).

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.

如果要在另一个页面(例如文本文件)中显示上载文件的内容,应该怎么办?

doPost()中调用response.sendRedirect()之前,请勿向响应中写入任何内容.让ajax和doGet()担心处理您之前谈论的那些"HTML标记".

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.

在相关说明中,您可能还会发现此答案很有趣:将HTML5文件上传到Java Servlet .

On a related note, you may find this answer interesting as well: HTML5 File Upload to Java Servlet.

这篇关于同时使用GET和POST的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆