sitelink1 | http://www.java-forums.org/advanced-java...-ajax.html |
---|---|
sitelink2 | |
sitelink3 | |
sitelink4 | http://1 |
extra_vars4 | ko |
extra_vars5 | |
extra_vars6 | sitelink1 |
Question : flush data from servlet to jsp with ajax
I've a servlet that process a file and reports the number of line which has processed. In the other side, I have a JSP, wit a div. This jsp uses Ajax to call the servlet.
The intended result, is that Ajax receives all the out.print of the Servlet and with javascript update an html table in the jsp.
I've been able to update the table and all that, but only after the servlet finish, all the lines that is printing, are not received in the ajax (or printed in the page) until this servlet finishes.
I understand that Ajax can monitor the status of the servlet, and as I can see, it finishes when status is 4 (completed) and result is 200 (OK). I'm sending from the servlet the out.print("text"), but as I said, the jsp process it when both 4 state and 200 status are received, nothing is received while the servlet is processing.
Can you help me with this please?
These are some code snippets:
Ajax
Java Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
|
And my servlet snippet:
Java Code:
1 2 3 4 5 6 7 |
|
Answer : Reply t flush data from servlet to jsp with ajax
I think you yourself gave the answer to it....
I understand that Ajax can monitor the status of the servlet, and as I can see, it finishes when status is 4 (completed) and result is 200 (OK). I'm sending from the servlet the out.print("text"), but as I said, the jsp process it when both 4 state and 200 status are received, nothing is received while the servlet is processing.
You don't receive the XmlHttpRequest object and so the responseText until the servlet you're calling via AJAX completes its execution! You might get a better view of it if u put a Thread.sleep(2000)....i.e., a delay of 2secs in your "for" loop
Java Code:
1 2 3 4 5 6 |
|
So, you cannot get any responseText while the servlet is processing. To achieve something like this, people tend to use a 'server push' method. You might like to see topics like 'Comet' also called Reverse Ajax, pushlets to get responses from the servlet to the client and u can use them your own way to achieve your goal!
good luck!! :)
댓글 0
번호 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|
177 | CORS(Cross-Origin Resource Sharing) - 3 | 황제낙엽 | 2017.03.07 | 45 |
176 | CORS(Cross-Origin Resource Sharing) - 2 | 황제낙엽 | 2017.03.07 | 24 |
175 | CORS(Cross-Origin Resource Sharing) - 1 | 황제낙엽 | 2017.03.07 | 135 |
174 | Jasmine 테스트 및 CI 구축 가이드 | 황제낙엽 | 2016.11.16 | 254 |
173 | QUnit을 이용한 JavaScript 단위 테스트 | 황제낙엽 | 2016.11.16 | 36 |
172 | code compressor & decompressor | 황제낙엽 | 2015.01.02 | 181 |
171 | 멤버 연산자 | 황제낙엽 | 2014.12.30 | 47 |
170 | 연산자 this | 황제낙엽 | 2014.12.30 | 23 |
169 | typeof 와 instanceof의 차이, 타입 또는 클래스 구분하기 | 황제낙엽 | 2013.10.24 | 38 |
168 | 링크모음 | 황제낙엽 | 2011.03.25 | 25 |
167 | 개요 | 황제낙엽 | 2009.03.11 | 28 |
166 | XMLHttpRequest.setRequestHeader | 황제낙엽 | 2013.09.30 | 62 |
165 | HTTP Content-Type 정리 | 황제낙엽 | 2013.09.30 | 68 |
164 | getBoundingClientRect in FF3 | 황제낙엽 | 2013.01.11 | 36 |
» | 연속해서 스트림 받기 (flush data from servlet to jsp with ajax) | 황제낙엽 | 2013.01.04 | 2428 |
162 | Stack (스택) 예제 프로그램 | 황제낙엽 | 2012.12.27 | 27 |
161 | 상속과 Super 로의 접근 | 황제낙엽 | 2012.09.18 | 64 |
160 | inherits() 를 이용한 상속 | 황제낙엽 | 2012.07.18 | 129 |
159 | Javascript delete | 황제낙엽 | 2012.06.11 | 20 |
158 | delete 연산자에 대한 고찰 | 황제낙엽 | 2012.06.11 | 42 |