I was trying to build an autocomplete text box in jsp page using Jquery plugin. But i am facing problem.
Whenever i was trying to display the list, it is not displaying.
When i was requesting for the jsp list page from JQuery Autocomplete, System.out is working, it is giving the relevant output but the same data should be displayed on the list, that is not happening.
my code goes like this
index.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Auto Complete TextBox</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="JS/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="JS/jquery.autocomplete.js"></script>
</head>
<body>
<input type="text" name="query" id="query" value="">
<script type="text/javascript">
var options, a;
jQuery(function(){
options = { serviceUrl:'list.jsp' };
a = $('#query').autocomplete(options);
});
/*$( "#query" ).autocomplete({
source: "list.jsp",
minLength: 1
});
*/
</script>
</body>
</html>
list.jsp
<%
String countries[] = {
"Afghanistan",
"Albania",
.
.
.
"Zambia",
"Zimbabwe"
};
String query = (String)request.getParameter("query");
//System.out.println("1"+request.getParameterNames().nextElement());
response.setHeader("Content-Type", "text/html");
for(int i=0;i<countries.length;i++)
{
if(countries[i].toUpperCase().startsWith(query.toUpperCase()))
out.print(countries[i]+"\n");
//System.out.print(countries[i]+"\n");
}
%>