zoukankan      html  css  js  c++  java
  • 搜索框智能提示

    servlet+ajax实现搜索框智能提示之servlet
    

    package com.imooc; import java.io.IOException; import java.util.ArrayList; import java.util.List; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import net.sf.json.JSONArray; public class SearchServlet extends HttpServlet { static List<String> datas=new ArrayList<String>(); static{ //这些是模拟数据 datas.add("ajax"); datas.add("ajax post"); datas.add("becky"); datas.add("bill"); datas.add("james"); datas.add("jerry"); } @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("utf-8"); response.setCharacterEncoding("utf-8"); //System.out.println("123"); //首先获得客户端发送来的数据keyword String keyword=request.getParameter("keyword"); //获得关键字之后进行处理,得到关联数据 List<String> listData=getData(keyword); //返回JSON格式 //System.out.println(JSONArray.fromObject(listData)); //["ajax","ajax post","james"] response.getWriter().write(JSONArray.fromObject(listData).toString()); } //获得关联数据的方法 public List<String> getData(String keyword){ List<String> list=new ArrayList<String>(); for(String data:datas){ if(data.contains(keyword)){ list.add(data); } } return list; }

      

  • 相关阅读:
    Ambari Server 架构
    [Spark]-源码解析-RDD之transform
    [Spark]-源码解析-RDD的五大特征体现
    [Spark]-作业调度与动态资源分配
    [Spark]-集群与日志监控
    [Spark]-Streaming-调优
    [Spark]-调优
    [Spark]-Streaming-Persist与CheckPoint
    [Spark]-Streaming-输出
    [Spark]-Streaming-操作
  • 原文地址:https://www.cnblogs.com/liujunzhe/p/8445056.html
Copyright © 2011-2022 走看看