大家好,我按照输入字段中的自动完成教程进行操作,但我遇到了问题。问题是一切正常,但下拉列表没有显示。
这是我的jsp:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ page language="java" import="java.util.*"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Καταχώρηση Εγγράφου</title>
<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" />
<script type="text/javascript"
src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript"
src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js"> </script>
<script type="text/javascript">
$(document).ready(function() {
$( "#apostoleas" ).autocomplete({
source: '${pageContext. request. contextPath}/articles/get_country_list.html'
});
});
</script>
<script type="text/javascript">
<body>
<h1 align="left"><font size="5"> <spring:message code="label.eggrafo" /></font></h1>
<c:url var="saveArticleUrl" value="/articles/saveeggrafo.html" />
<form:form name="sds" enctype="multipart/form-data" onsubmit="return validateForm()" modelAttribute="eggrafo" method="POST" action="${saveArticleUrl}">
<table style=" min-height:570px; height:570px;min-width:570px; width:570px; " bgcolor="990099">
<tr>
<th style="display:none">Id</th>
</tr>
<tr>
<th style="display:none"><form:input readonly="true" path="idtypiko" /></th>
</tr>
<tr>
<th style="display:none">User</th>
</tr>
<tr>
<th style="display:none"><form:input path="username" value="${username}" /></th>
</tr>
<tr>
<th><FONT SIZE="5" FACE="courier" ><spring:message code="label.etos" /></FONT></th>
</tr>
<tr>
<th><form:input cssStyle="width: 420px;height: 30px;font-size : 1.0em;" id="etos" path="year" value="${year}"/></th>
</tr>
<tr>
<th><FONT SIZE="5" FACE="courier" ><spring:message code="label.fakelos" /></FONT></th>
</tr>
<tr>
<th><form:input cssStyle="width: 420px;height: 30px;font-size : 1.0em;" path="fakelos_eggrafou" id="fakelos_eggrafou" /></th>
<%--<th><form:select class="styled-select" path="fakelos_eggrafou" >
<OPTION onclick="javascript:mine();" selected="selected" VALUE=""><c:out value="Άλλο"/></OPTION>
<c:forEach items="${fakeloi}" var="fake">
<OPTION onclick="javascript:form();" VALUE="${fake}"><c:out value="${fake}"/></OPTION>
</c:forEach>
</form:select></th> --%>
</tr>
<tr>
<th><FONT SIZE="5" FACE="courier" ><spring:message code="label.diab" /></FONT></th>
</tr>
<tr>
<th><form:select class="styled-select" path="diabathmisi">
<c:forEach items="${diabathmiseis}" var="diab">
<OPTION VALUE="${diab.onoma}"><c:out value="${diab.onoma}"/></OPTION>
</c:forEach>
</form:select></th>
</tr>
<tr>
<th><FONT SIZE="5" FACE="courier" ><spring:message code="label.apostol" /></FONT></th>
</tr>
<tr>
<%-- <th>
<form:select id="apostoleas" class="styled-select1" path="apostoleas">
<c:forEach items="${apostoleis}" var="apost">
<OPTION VALUE="${apost.apostoleas}"><c:out value="${apost.apostoleas}"/></OPTION>
</c:forEach>
</form:select>
</th> --%>
<td><form:input id="apostoleas" path="apostoleas" /></td>
</tr>
<tr>
<th><FONT SIZE="5" FACE="courier" ><spring:message code="label.tauteg" /></FONT></th>
</tr>
<tr>
<th><form:input cssStyle="width: 420px;height: 30px;font-size : 1.0em;" id="tautotitaegg" path="tautotitaeg" /></th>
</tr>
<tr>
<th><FONT SIZE="5" FACE="courier" ><spring:message code="label.thema" /></FONT></th>
</tr>
<tr>
<th><form:input cssStyle="width: 420px;height: 30px;font-size : 1.0em;" path="thema" /></th>
</tr>
<tr>
<th><FONT SIZE="5" FACE="courier" ><spring:message code="label.sinimena" /></FONT></th>
</tr>
<tr>
<th><form:input cssStyle="width: 420px;height: 30px;font-size : 1.0em;" path="sinimena" /></th>
</tr>
<tr>
<th><FONT SIZE="5" FACE="courier" ><spring:message code="label.hmerypogr" /></FONT></th>
</tr>
<tr>
<th> <input style="width: 420px;height: 30px;font-size : 1.0em;" value="${date}" name="hmeromhniaypog" id="datepick" class="date-pick"/>
<script type="text/javascript">
datepickr('datepick', { dateFormat: 'Y-m-d' });
</script></th>
</tr>
<tr>
<th><FONT SIZE="5" FACE="courier" >Αρχείο</FONT></th>
</tr>
<tr>
<th><form:input cssStyle="width: 420px;height: 30px;font-size : 1.0em;" path="file" type="file" id="file"/></th>
</tr>
<tr>
<th><FONT SIZE="5" FACE="courier" ><spring:message code="label.parat" /></FONT></th>
</tr>
<tr>
<th><form:textarea cssStyle="width: 420px;height: 30px;font-size : 1.0em;" cols="30" rows="3" path="parathrhseis" /></th>
</tr>
<tr>
</table>
<br />
<input name="s" class="groovybutton" onMouseOver="goLite(this.form.name,this.name)" onMouseOut="goDim(this.form.name,this.name)" type="submit" value="<spring:message code="label.button" />" />
</form:form>
</body>
这是控制器部分:
@RequestMapping(value = "/get_country_list",
method = RequestMethod.GET,
headers="Accept=*/*")
public @ResponseBody List<String> getCountryList(@RequestParam("term") String query) {
List<String> countries;
String data = "Afghanistan, Albania, Algeria, Andorra, Angola, Antigua & Deps,"+
"Argentina, Armenia, Australia, Austria,Azerbaijan,Bahamas,Bahrain,Bangladesh,Barbados,"+
"Belarus,Belgium,Belize,Benin,Bhutan,Bolivia,Bosnia Herzegovina,Botswana,Brazil,Brunei,"+
"Bulgaria,Burkina,Burundi,Cambodia,Cameroon,Canada,Cape Verde,Central African Rep,Chad,"+
"Chile,China,Colombia,Comoros,Congo,Congo {Democratic Rep},Costa Rica,Croatia,Cuba,Cyprus,"+
"Czech Republic,Denmark,Djibouti,Dominica,Dominican Republic,East Timor,Ecuador,Egypt,El Salvador,"+
"Equatorial Guinea, Eritrea,Estonia,Ethiopia,Fiji,Finland,France,Gabon,Gambia,Georgia,Germany,"+
"Ghana, Greece, Grenada,Guatemala,Guinea,Guinea-Bissau,Guyana,Haiti,Honduras,Hungary,Iceland,"+
"India, Indonesia,Iran,Iraq,Ireland {Republic},Israel,Italy,Ivory Coast,Jamaica,Japan,"+
"Jordan,Kazakhstan,Kenya,Kiribati,Korea North,Korea South,Kosovo,Kuwait,Kyrgyzstan,Laos,"+
"Latvia,Lebanon,Lesotho,Liberia,Libya,Liechtenstein,Lithuania,Luxembourg,Macedonia,Madagascar,"+
"Malawi,Malaysia,Maldives,Mali,Malta,Marshall Islands,Mauritania,Mauritius,Mexico,Micronesia,"+
"Moldova,Monaco,Mongolia,Montenegro,Morocco,Mozambique,Myanmar {Burma},Namibia,Nauru,Nepal,"+
"Netherlands,New Zealand,Nicaragua,Niger,Nigeria,Norway,Oman,Pakistan,Palau,Panama,Papua New Guinea,"+
"Paraguay,Peru,Philippines,Poland,Portugal,Qatar,Romania,Russian Federation,Rwanda,St Kitts & Nevis,"+
"St Lucia,Saint Vincent & the Grenadines,Samoa,San Marino,Sao Tome & Principe,Saudi Arabia,Senegal,"+
"Serbia,Seychelles,Sierra Leone,Singapore,Slovakia,Slovenia,Solomon Islands,Somalia,South Africa,"+
"Spain,Sri Lanka,Sudan,Suriname,Swaziland,Sweden,Switzerland,Syria,Taiwan,Tajikistan,Tanzania, "+
"Thailand,Togo,Tonga,Trinidad & Tobago,Tunisia,Turkey,Turkmenistan,Tuvalu,Uganda,Ukraine,United Arab Emirates,"+
"United Kingdom,United States,Uruguay,Uzbekistan,Vanuatu,Vatican City,Venezuela,Vietnam,Yemen,Zambia,Zimbabwe";
countries = new ArrayList<String>();
StringTokenizer st = new StringTokenizer(data, ",");
//Parse the country CSV list and set as Array
while(st.hasMoreTokens()) {
countries.add(st.nextToken().trim());
}
String country = null;
query = query.toLowerCase();
List<String> matched = new ArrayList<String>();
for(int i=0; i < countries.size(); i++) {
country = countries.get(i).toLowerCase();
if(country.startsWith(query)) {
matched.add(countries.get(i));
}
}
System.out.println(matched);
return matched;
}
有谁知道问题出在哪里?
我按照本教程 http://viralpatel.net/blogs/spring-3-mvc-autocomplete-json-tutorial/
我还检查了萤火虫返回的内容并返回以下内容:
GET http://localhost:8080/Spring3Hibernate/articles/get_country_list.html?term=5
406 不可接受 66ms
此请求标识的资源只能生成具有根据请求“接受”标头不可接受的特征的响应。