Method | Description |
---|---|
abort() | Stops the current request |
getAllResponseHeaders() | Returns complete set of headers (labels and values) as a string |
getResponseHeader("headerLabel") | Returns the string value of a single header label |
open("method", "URL"[, asyncFlag[, "userName"[, "password"]]]) | Assigns destination URL, method, and other optional attributes of a pending request |
send(content) | Transmits the request, optionally with postable string or DOM object data |
setRequestHeader("label", "value") | Assigns a label/value pair to the header to be sent with a request |
Property | Description |
---|---|
onreadystatechange | Event handler for an event that fires at every state change |
readyState | Object status integer: 0 = uninitialized 1 = loading 2 = loaded 3 = interactive 4 = complete |
responseText | String version of data returned from server process |
responseXML | DOM-compatible document object of data returned from server process |
status | Numeric code returned by server, such as 404 for "Not Found" or 200 for "OK" |
statusText | String message accompanying the status code |
<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; } } } } </script> <form name="myForm"> Name: <input type="text" name="username" /> Time: <input type="text" name="time" /> </form> </body> </html> |
xmlHttp.onreadystatechange=function() { // some code here } |
xmlHttp.onreadystatechange=function() { if(xmlHttp.readyState==4) { // some code here } } |
xmlHttp.onreadystatechange=function() { if(xmlHttp.readyState==4) { document.myForm.time.value=xmlHttp.responseText; } } |
xmlHttp.open("GET","trustdir.jsp",true); xmlHttp.send(null); |
<form name="myForm"> Name: <input type="text" name="username" onkeyup="ajaxFunction();"/> Time: <input type="text" name="time" /> </form> |
<% out.print("Now: "+new java.util.Date()); %> |
/ajax/timestamp.jsp |
---|
<%@ page import="java.util.Date" %> <% try { String t = request.getParameter("t"); if (t==null | t.trim().length()==0) t="0"; java.util.Date dt = new Date(Long.parseLong(t)); out.print(dt.toString()); } catch (Exception e) { out.print("Invalid input"); } %> |
<html> <head> <script type="text/javascript"> var ns=(document.layers); var ie=(document.all); var w3=(document.getElementById && !ie); function GetXmlHttpObject() { var xmlHttp=null; try { xmlHttp=new XMLHttpRequest(); } catch (e) { try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } } return xmlHttp; } function ajaxConverter() { var xmlHttp = GetXmlHttpObject(); xmlHttp.onreadystatechange=function() { if(xmlHttp.readyState==4) { var adDiv; if(ie) adDiv=eval('document.all.divConverter.style'); else if(ns) adDiv=eval('document.layers["divConverter"]'); else if(w3) adDiv=eval('document.getElementById("divConverter").style'); if (xmlHttp.responseText!="") { document.getElementById("divConverter").innerHTML=xmlHttp.responseText; if (ie||w3) { adDiv.visibility="visible"; adDiv.display=""; } else adDiv.visibility ="show"; } } } xmlHttp.open("GET","/ajax/timestamp.jsp?t="+document.frmConverter.t.value,true); xmlHttp.send(null); } </script> </head> <body> <form name="frmConverter"> <table> <tr> <td><input type="text" name="t" style='border:1px solid gray;font-size:13px;' value="" onkeyup="ajaxConverter()"></td> <td><div id="divConverter" style="display:none;visibility:hidden;color:blue;font-size:13px;font-weight:bold;"></div></td> </tr> </table> </form> </body> </html> |
import javax.crypto.Cipher; import javax.crypto.KeyGenerator; import javax.crypto.SecretKey; import javax.crypto.spec.SecretKeySpec; public class VicCrypt { private static KeyGenerator kgen; private static Cipher cipher; private static boolean initiated=false; private static VicCrypt crypt = new VicCrypt(); private static void init() { try { kgen = KeyGenerator.getInstance("Blowfish"); cipher = Cipher.getInstance("Blowfish"); initiated=true; } catch (Exception e) { } } public static VicCrypt getInstance() { if (!initiated) init(); return crypt; } public static byte [] getKey() throws Exception { SecretKey skey = kgen.generateKey(); return skey.getEncoded(); } public static byte [] encrypt(byte[] key, String token) throws Exception { SecretKeySpec skeySpec = new SecretKeySpec(key, "Blowfish"); cipher.init(Cipher.ENCRYPT_MODE, skeySpec); return cipher.doFinal(token.getBytes()); } public static byte [] decrypt(byte[] key, String token) throws Exception { SecretKeySpec skeySpec = new SecretKeySpec(key, "Blowfish"); cipher.init(Cipher.DECRYPT_MODE, skeySpec); return cipher.doFinal(token.getBytes()); } }