import net.sf.json.JSONArray; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.util.*; 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"); datas.add("hao"); } @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException,IOException{ request.setCharacterEncoding("utf-8"); response.setCharacterEncoding("utf-8"); System.out.print("123"); //获取客户端数据 String keyword = request.getParameter("keyword"); //获取关键字 List<String> listData = getData(keyword); //返回json格式 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; } }

Tg171017 LV12
2023年1月9日
jwfadacai LV8
2022年5月11日
1973356987 LV13
2021年6月17日
小白jmhuang LV12
2021年4月14日
lan12138 LV8
2021年3月24日
123hzh LV5
2020年11月19日
邈话12123 LV9
2020年10月29日
果园6666 LV5
2020年6月26日
小仙女本仙haha LV8
2020年6月13日
13940562934 LV22
2020年6月3日

a2796831202
2023年12月20日
暂无贡献等级
你爹正在加载中 LV4
2023年7月18日
ling7314 LV4
2023年7月6日
三十一 LV2
2023年6月28日
Sleachp LV8
2023年5月5日
chen_jw LV10
2023年2月19日
Tg171017 LV12
2022年12月25日
微信网友_6191697646571520 LV6
2022年11月24日
微信网友_6040315240812544 LV8
2022年10月11日
憨豆先生 LV2
2022年5月12日