No Output while AutoComplete InputText with JSP and jQuery

295 views Asked by At

I want to create an autocomplete input text for the list of city. I am getting output in the JSP page (checked) but I don't know how to get back response to requested page in edit text suggestion.

Here is my code :

index.jsp (A file with edit text and JavaScript plugin)

$("#city").autocomplete("indexEditText.jsp");
<html>
<link rel="stylesheet" type="text/css" href="https://pengoworks.com/workshop/jquery/lib/jquery.autocomplete.css" />
 <script type="text/javascript" 
   src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
 <script src="https://pengoworks.com/workshop/jquery/lib/jquery.autocomplete.js"></script>  
 
</head>
<body>
 <h3>City</h3>
 <input type="text" id="city" name="city"/>
 
 
</body>
</html>

indexEditText.jsp

   <%
        List<String> l = ConnectionProvider.getData(request.getParameter("city"));
        Iterator<String> iterator = l.iterator();
        String[] city=null;
        int i=0;
        while(iterator.hasNext()) {
        city[i]= (String)iterator.next();   
        out.println(city[i]);
        i++;
    }
        /*  String json = new Gson().toJson(l);
         response.getWriter().write(json); */
    %>
1

There are 1 answers

0
Nilay On

I find the easy alternative way of autocomplete text view.i was unable to resolve the above way of getting it.

We can use the <datalist> tag of HTML5 and fill the data in the list with the help of script/code whatever you use to retrieve.Here I used java and JSP page for the view.

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%
List<String> l = ConnectionProvider.getData();
%>
<input list="citylist" name="city">
<datalist id="citylist">
<%for(String s : l)
    {System.out.println(s);
    %>
        <option value=<%=s%>>
<%  }
%>
 <option value="Internet Explorer">
    <option value=<% %>>

</datalist>


</body>
</html>

Besides these to improve the performance you can use the sql indexing , secondary level cache.