Skip to content

Instantly share code, notes, and snippets.

@sjyun
Created May 7, 2014 09:17
Show Gist options
  • Select an option

  • Save sjyun/847f6089141df4703e96 to your computer and use it in GitHub Desktop.

Select an option

Save sjyun/847f6089141df4703e96 to your computer and use it in GitHub Desktop.
async CLient jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>비동기요청페이지</title>
</head>
<body>
<h1>서블릿 비동기 테스트</h1>
<form method="POST" action="async">
<table>
<tr>
<td>이름을 입력하세요.</td>
<td><input type="text" id="name" name="name"/></td>
</tr>
<tr>
<td>메시지를 입력하세요</td>
<td><input type="text" id="message" name="message" /></td>
</tr>
<tr>
<td><input type="submit" value="async" /></td>
</tr>
</table>
</form>
<h2> 현재출력내용 </h2>
<div id="content">
<% if (application.getAttribute("messages") != null) {%>
<%= application.getAttribute("messages")%>
<% }%>
</div>
<script>
var messagesWaiting = false;
function getMessages(){
if(!messagesWaiting){
messagesWaiting = true;
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange=function(){
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
messagesWaiting = false;
var contentElement = document.getElementById("content");
contentElement.innerHTML = xmlhttp.responseText + contentElement.innerHTML;
}
}
xmlhttp.open("GET", "async?t="+new Date(), true);
xmlhttp.send();
}
}
setInterval(getMessages, 1000);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment