日期:2014-05-16 浏览次数:20628 次
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Struts 2 Ajax Google</title>
<script type='text/javascript' src='/struts2ajaxgoogle/dwr/engine.js'></script>
<script type='text/javascript'
src='/struts2ajaxgoogle/dwr/interface/KeyWrod.js'></script>
<script type='text/javascript' src='/struts2ajaxgoogle/dwr/util.js'></script>
<script type="text/javascript" src="./jq/jquery-1.6.2.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#search").keyup(function() {
var key = $("#search").val();
KeyWrod.getName(key, callback); });
function callback(date) {
var key = "";
for (i = 0; i < date.length; i++) {
key = key + date[i][1]+ "</br>";
}
$("#result").html("<br>"+key+"</br>");
}
});
</script>
</head>
<body>
<center>
<img style="padding-top: 58px;" src="img/1.jpg">
<br />
<br />
<input type="text" id="search"
style="width: 600px; height: 38px; font-size: 20px; font-weight: bold;" />
<input type="button" id="sub" value="Google Search"
style="height: 40px;" />
<br />
<div id="result"></div>
</center>
</body>
</html>
package action;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.opensymphony.xwork2.ActionSupport;
import dao.Db;
public class KeyAction extends ActionSupport {
/**
*
*/
private static final long serialVersionUID = 1L;
public List getName(String key) throws Exception {
Db db = new Db();
ResultSet rs = db.getKeyWord(key);
List list = new ArrayList();
List tempList = new ArrayList();
ResultSetMetaData md = rs.getMetaData();
int columnCount = md.getColumnCount();
while (rs.next()) {
for (int i = 1; i <= columnCount; i++) {
tempList.add(rs.getObject(i));
}
list.add(tempList);
}
return list;
}
}