Uncaught SyntaxError: Unexpected end of input and Java null exception error for devbridge autocomplete

Uncaught SyntaxError: Unexpected end of input and Java null exception error for devbridge autocomplete

我已经多次使用 DAO,所以我不认为错误来自那里,我认为错误可能是因为 JSON。我是 JSON.

的新手

GLASSFISH 服务器输出:NULL EXCEPTION.. 打印 SupplierID INT 时,它打印 null

HTML 代码

<div>
    <div>
        <input type="text" name="search" id="autocomplete-ajax"  placeholder="Enter Country name"/>
    </div>
    <div id="selection" ></div>
</div>

SERVLET 代码

try (PrintWriter out = response.getWriter()) {
        /* TODO output your page here. You may use following sample code. */

        String supplierID = request.getParameter("search");
        System.out.println("Hello from Get Method: " + supplierID);
        int supplierIDInt = Integer.parseInt(supplierID);

        ArrayList<RefSupplier> RefSupplierList = new RefSupplierDAO().getSupplier(supplierIDInt);
       Gson gson = new Gson();
        JSONArray array = new JSONArray();
        for (int i = 0; i < RefSupplierList.size(); i++) {
            JSONObject obj = new JSONObject();
            try {
                obj.put("supplierID", RefSupplierList.get(i).getSupplierID());
                obj.put("itemCode", RefSupplierList.get(i).getItemCode());
                obj.put("itemName", RefSupplierList.get(i).getItemName());
                obj.put("companyName", RefSupplierList.get(i).getCompanyName());
                obj.put("companyAddress", RefSupplierList.get(i).getCompanyAddress());
                obj.put("contactPerson", RefSupplierList.get(i).getContactPerson());
                obj.put("contactNumber", RefSupplierList.get(i).getContactNumber());
                array.put(obj);

            } catch (JSONException ex) {
                Logger.getLogger(GetSuppliersAndItemForSuppliersServlet.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
             String json = gson.toJson(array);
         System.out.println(json);
        response.getWriter().write(json);

    }

JQUERY 代码

<script type="text/javascript">
    $(document).ready(function () {
        $("#autocomplete-ajax").autocomplete({
            serviceUrl: 'GetSupplierItemForBillOfMaterialsServlet', //tell the script where to send requests
            type: 'POST',
            onSelect: function (suggestion) {
                $('#selection').html('You selected: ' + suggestion.value + ', ' + suggestion.data);
            },
            showNoSuggestionNotice: true,
            noSuggestionNotice: 'Sorry, no matching results',
        });
    });
</script>

devbridge 插件的默认设置应该是查询而不是搜索

字符串供应商 ID = request.getParameter("query");下面右边的代码