468x60

martedì 29 dicembre 2009

JSP e AJAX

Esempio di codice per interazione Client-Server utilizzando JSP e AJAX:

//ajaxTest.html
<html><body><script type="text/javascript">function ajaxFunction()
{var xmlHttp;
try
{ // Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest(); }
catch (e)
{ // Internet Explorer try
{ xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); }
catch (e)
{ try
{ xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); }
catch (e)
{ alert("Your browser does not support AJAX!"); return false; } } }
xmlHttp.onreadystatechange=function()
{
if(xmlHttp.readyState==4)
{
document.myForm.time.value=xmlHttp.responseText;
}
}
xmlHttp.open("GET","time.jsp",true);
xmlHttp.send(null); }</script><form name="myForm">
Name: <input type="text"
onkeyup="ajaxFunction();" name="username" />
Time: <input type="text" name="time" />
</form></body>
</html>

//time.jsp
<%
// This scriptlet declares and initializes "date"
java.util.Date date = new java.util.Date();
%>
<%=date%>

Nessun commento:

Posta un commento

468x60

Cerca su Google

Cerca nel Blog con Google