0

こんにちは皆さん、入力フィールドでオートコンプリートのチュートリアルに従っていますが、問題があります。問題は、すべて問題ないのに、ドロップダウン リストが表示されないことです。

これが私の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"> &nbsp;<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/

また、どのfirebugが返すかを確認し、次を返します:

GET http://localhost:8080/Spring3Hibernate/articles/get_country_list.html?term=5

406 受け入れられない 66ms

この要求によって識別されるリソースは、要求の「受け入れ」ヘッダーに従って受け入れられない特性を持つ応答を生成することしかできません。

4

1 に答える 1

2
@RequestMapping(value = "/getProductAutoCompleteList.do", method = RequestMethod.GET, headers="Accept=*/*")
    public @ResponseBody List<String> getProductAutoComplete(@RequestParam("term") String prodName, HttpServletResponse response){
        logger.info("getProductAutoCompleteList called with parameter: " + prodName);
        response.setStatus(HttpServletResponse.SC_OK);
        final List<String> productList = ProductSearchHelper.getProductAutoCompleteList(prodName);


        response.setContentType("application/json");
        return productList;
    }

確認してください

  1. response.setStatus(HttpServletResponse.SC_OK); を指定します。コントローラーメソッドで
  2. オプション、setContentType を application/json として設定
  3. @ResponseBody アノテーションを持つ Spring MVC は、Jackson JSON プロセッサー上に構築された MappingJacksonHttpMessageConverter を呼び出します。クラスパスに Jackson が存在する mvc:annotation-driven 構成要素を使用すると、この実装は自動的に有効になります。
于 2013-01-31T15:59:29.647 に答える