ColdFusion, AJAX and web...
You have reached this web page by typing "example.com", "example.net", or "example.org" into your web browser. These domain names are reserved for use in documentation and are not available for registration. See RFC 2606, Section 3.
<cfquery datasource="cfartgallery" name="qArtists">
SELECT *
FROM artists
ORDER BY lastname, firstname
</cfquery>
<cfoutput query="qArtists">
ID: #qArtists.artistid#<br/>
Last name: #qArtists.lastname#<br/>
First name: #qArtists.firstname#<br/>
<br/>
</cfoutput>
Java code
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
Connection conn = DriverManager.getConnection("jdbc:odbc:artgallery");
Statement smnt = conn.createStatement();
ResultSet res = smnt.executeQuery("SELECT * FROM artists " +
"ORDER BY lastname, firstname");
while(res.next())
{
System.out.println("ID:" + res.getInt("artistid"));
System.out.println("Last name:" + res.getString("lastname"));
System.out.println("First name:" + res.getString("firstname"));
System.out.println();
}
conn.close();
}
catch (SQLException se)
{
System.out.println("SQLException: " + se.getMessage());
}
catch (Exception e)
{
System.out.println("Exception: " + e.getMessage());
}
<html>
<head>
<title>JSON Test</title>
<script src="artists.js"></script>
</head>
<body>
<a href="javascript:getArtists()">Call getArtists() method -- appends to table!</a>
<br/><br/>
<table id="artistTable">
<caption>Artists</caption>
<thead>
<tr>
<td>ID</td>
<td>Last Name</td>
<td>First Name</td>
<td>City</td>
</tr>
</thead>
</table>
<script>
getArtists();
</script>
</body>
</html>
artists.js
This JavaScript file contains methods that will dynamically create the SCRIPT tag. The src attribute of the SCRIPT tag is the getData.cfm ColdFusion template, which creates the JavaScript data.
The populateUI method (which populates the table with the data) is only called once the SCRIPT tag's readyState has changed to "loaded".
function getDataFromServer(id, url, callback)
{
oScript = document.getElementById(id);
var head = document.getElementsByTagName("head").item(0);
if (oScript)
{
// Destory object
head.removeChild(oScript);
}
// Create object
oScript = document.createElement("script");
var dtRf = new Date();
oScript.setAttribute("src",url + "?rf=" +dtRf.getTime());
oScript.setAttribute("id",id);
head.appendChild(oScript);
if (oScript.readyState!="loaded")
{
oScript.onreadystatechange = function()
{
if (this.readyState == "loaded")
{
eval(callback);
oScript.onreadystatechange = null;
}
}
}
else
{
alert('Cannot load data!');
}
}
function getArtists()
{
getDataFromServer("artistData","getData.cfm","populateUI()");
}
function populateUI()
{
oTable = document.getElementById("artistTable");
// Loop over the data in the JS array, and add to table
for (var i=0; i < aData.length; i++)
{
// Create a new TR element
oTR = oTable.insertRow();
// Create a call for each element in struct
oTD = oTR.insertCell();
oTD.innerHTML = aData[i].artistid;
oTD = oTR.insertCell();
oTD.innerHTML = aData[i].lastname;
oTD = oTR.insertCell();
oTD.innerHTML = aData[i].firstname;
oTD = oTR.insertCell();
oTD.innerHTML = aData[i].city;
}
}
getData.cfm
This ColdFusion template performs a query on the artist database. The query is then converted to an Array of Structures (using QueryToArrayOfStructures from cflib.org), and then converted to JavaScript using the CFWDDX tag.
I am not *really* using JSON here. But, by using the bult-in ColdFusion JavaScript conversion functionality in the CFWDDX tag, you achieve the same result, it's just not as light-weight.
<cfsetting enablecfoutputonly="true">
<cfquery datasource="cfartgallery" name="qData">
SELECT *
FROM artists
ORDER BY lastname, firstname
</cfquery>
<cfwddx action="cfml2js" input="#QueryToArrayOfStructures(qData)#" output="jscontent" toplevelvariable="aData">
<cfoutput>#jscontent#</cfoutput>
There you have it! I'm pretty sure this code shall work, and I welcome any comments or improvements. It was put together pretty quickly!
<cfcomponent>
<cffunction name="arrayOfStructures">
<cfscript>
var aData = ArrayNew(1);
var stItem = StructNew();
var i = 1;
for (i=1; i LTE 10; i=i+1)
{
stItem = StructNew();
stItem.name = "Item " & i;
stItem.description = "Description " & i;
ArrayAppend(aData, stItem);
}
for (i=1; i LTE ArrayLen(aData); i=i+1)
{
writeoutput(aData[i].name & " : " & aData[i].description & "<br/>");
}
</cfscript>
</cffunction>
</cfcomponent>
Java code
import java.util.*;
public class ArrayListLoop {
public static void main (String args[])
{
ArrayList<HashMap> al = new ArrayList<HashMap>();
HashMap<String, String> h = new HashMap<String, String>();
Integer i;
for (i=1; i <= 10; i++) {
h = new HashMap<String, String>();
h.put("name", "Item" + i);
h.put("description", "Description" + i);
al.add(h);
}
Iterator it = al.iterator();
while (it.hasNext())
{
// Putting (type) before "casts" it
HashMap thisMap = (HashMap) it.next();
System.out.println(thisMap.get("name") + " : " + thisMap.get("description"));
} // end while loop
} // end main() method
} // end class
Firefox has to move from "evangelising to the sandals and start evangelising to the suits" to sustain growth, Ovum's Barnett says.
Link prefetching is a browser mechanism, which utilizes browser idle time to download or prefetch documents that the user might visit in the near future. A web page provides a set of prefetching hints to the browser, and after the browser is finished loading the page, it begins silently prefetching specified documents and stores them in its cache. When the user visits one of the prefetched documents, it can be served up quickly out of the browser's cache.All you have to do is place this in your code:
<link rel="prefetch" href="/images/big.jpeg">
<link rel="prefetch" href="http://www.mozilla.org/projects/netlib/
Link_Prefetching_FAQ.html">
This opens up possibilities for developers to go and get content before a user has even requested it. However, it also opens up the possibilties for abuse. For instance, what if I decided to create a page that went and prefetched 10x10 MB images. Now, for someone like myself, who only has 200 MB bandwidth per month (blame Telstra!), this would be a big problem!
I think they really should have limited the functionality so that you can only pre-fetch content from the same server the originating page resides. This would at least limit the exposure to such abuses.
You can disable link prefetching by modifying the prefs.js file.
user_pref("network.prefetch-next",false);
Storage is an important part of email, but that doesn't mean you should have to worry about it. To celebrate our one-year birthday, we're giving everyone one more gigabyte. But why stop the party there? Our plan is to continue growing your storage beyond 2GBs by giving you more space as we are able. We know that email will only become more important in people's lives, and we want Gmail to keep up with our users and their needs. From Gmail, you can expect more.April fools? I hope not.
<select>
<optgroup label="Group 1">
<option value="1">Item 1</option>
<option value="2">Item 2</option>
</optgroup>
<optgroup label="Group 2">
<option value="3">Item 3</option>
<option value="4">Item 4</option>
</optgroup>
</select>