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 d开发者_如何学Pythono? ( 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 progressHTML 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.
精彩评论