Listing 1: resolveZip.jsp

<%@ page info="resolveZip" %>
<%@page import="java.util.Properties"%>

<%
	String lookupType = request.getParameter("lookupType");

	Properties properties = (Properties)getServletContext().getAttribute(lookupType);

	if (properties == null)
	{
		properties = new Properties();
		try {
        		properties.load(new java.io.FileInputStream("c:\\" + lookupType +
				 ".property"));
			getServletContext().setAttribute(key, properties);
		} catch (java.io.IOException e) {
			out.println("Property File not found");
		}
	}
	out.println(properties.getProperty(request.getParameter("zip")));%>


Listing 2: zipsearch.html (IFRAME)

Zip:<input  id="zipcode" type="text" maxlength="5"  onKeyUp="zipchanged()"
 style="width:60" size="20"/>
City: <input id="city" disabled maxlength="32" style="width:160" size="20"/>
State:<input id="state" disabled maxlength="2" style="width:30" size="20"/>
<iframe id="controller" style="visibility:hidden;width:0;height:0"></iframe>

<script src="iframe.js"></script>
<script>
var zipField = null;
function zipchanged(){
	zipField = document.getElementById("zipcode")
	var zip = zipField.value;
	zip.length == 3?updateState(zip):zip.length == 5?updateCity(zip):"";

}
function updateState(zip) {
	var stateField = document.getElementById("state");
	ask("resolveZip.jsp?lookupType=state&zip="+zip, stateField, zipField);
}
function updateCity(zip) {
	var cityField = document.getElementById("city");
	ask("resolveZip.jsp?lookupType=city&zip="+zip, cityField, zipField);
}
</script>


Listing 3: iframe.js

function response(result, fieldToFill, lookupField)
{
	var lookup = document.getElementById(lookupField);
	var fill = document.getElementById(fieldToFill);

	if ( result == "null" ) {
		lookup.style.borderColor = "red";
		fill.value = "";
	} else {
		lookup.style.borderColor = "";
		fill.value = result;
	}
}


function ask(url, fieldToFill, lookupField)
{
	var controller = document.getElementById("controller");
	controller.src = url+"&field="+fieldToFill.id+"&lookup="+lookupField.id;
}


Listing 4: resolveZip.jsp (IFRAME)

<%@ page info="resolveZip" %>
<%@page import="java.util.Properties"%>

<script>
<%
	String lookupType = request.getParameter("lookupType");

	Properties properties = (Properties)getServletContext().getAttribute(lookupType);

	if (properties == null)
	{
		properties = new Properties();
		try {
        		properties.load(new java.io.FileInputStream("c:\\" + lookupType +
				 ".property"));
			getServletContext().setAttribute(key, properties);
		} catch (java.io.IOException e) {
			out.println("Property File not found");
		}
	}

	out.println("var field= '" + request.getParameter("field") +"'");
	out.println("var lookup= '" + request.getParameter("zip") +"'");
	out.println("var result= '" + properties.getProperty(request.getParameter("zip"))
	 +"'");%>
	window.top.window.response(result, field, lookup);
</script>

Listing 7. city.properties

..........
01243=Middlefield
01244=Mill River
01245=Monterey
01247=North Adams
01252=North Egremont
01253=Otis
01254=Richmond
01255=Sandisfield
01256=Savoy
………….

Listing 8. state.properties

. . . . . .
894=NV
895=NV
897=NV
898=NV
900=CA
901=CA
902=CA
903=CA
904=CA
905=CA

Listing 9. readyState values

0 (UNINITIALIZED) The object has been created, but not initialized (the open method has not
been called).

(1) LOADING The object has been created, but the send method has not been called.

(2) LOADED The send method has been called, but the status and headers are not yet
available.

(3) INTERACTIVE Some data has been received. Calling the responseBody and
responseText properties at this state to obtain partial results will return an error,
because status and response headers are not fully available.

(4) COMPLETED All the data has been received, and the complete data is available in the
responseBody and responseText properties