출처 : http://www.otl.pe.kr/my/view.php?idx=940
한동안 안써서 까먹어서 새로 학습합니다.
버전이 1.6이 나왔었군요.
http://prototype.conio.net
http://openframework.or.kr/framework_reference/prototype_js/1.5.0/prototype.js.html
2가지 방법으로 구현합니다.
* index1.jsp
<%@ page contentType="text/html; charset=utf-8" %>
<script src="prototype.js"></script>
<script>
function send(){
var pars = 'content='+$F('content');
var ajax = new Ajax.Request(
'insert.jsp',
{
method:'post',
parameters:pars,
onFailure:reportError,
onComplete:showList
});
}
function reportError(request){
alert('error');
}
function showList(request){
$('content').value = '';
$('list').innerHTML = request.responseText;
}
</script>
<div id=list></div>
<form name=frm>
<textarea name=content rows=5 cols=80></textarea>
<input type=button onclick="send();" value="확인">
</form>
* index2.jsp
<%@ page contentType="text/html; charset=utf-8" %>
<script src="prototype.js"></script>
<script>
function send(){
var pars = 'content='+$F('content');
var ajax = new Ajax.Updater(
{success: 'list'},
'insert.jsp',
{
method:'post',
parameters:pars,
onFailure:reportError
});
}
function reportError(request){
alert('error');
}
</script>
<div id=list></div>
<form name=frm>
<textarea name=content rows=5 cols=80></textarea>
<input type=button onclick="send();" value="확인">
</form>
* insert.jsp
<%@ page contentType="text/html; charset=utf-8" %>
<%@ page import="java.util.*" %>
<%
List list = (List)session.getAttribute("list");
if(list == null) list = new ArrayList();
String content = request.getParameter("content");
System.out.println(content);
list.add(content);
session.setAttribute("list", list);
%>
<table border=1 width=100%>
<%
for(Object o:list){
%>
<tr>
<td><%=o.toString() %></td>
</tr>
<%
}
%>
</table>