js+servlet实现百度搜索栏下拉框的实现

2021-03-30 22:27

阅读:680

YPE html>

标签:button   extends   解析   har   remove   color   width   tps   lsp   

技术图片

 

 

前端代码

"Content-Type" content="text/html; charset=UTF-8">
    s
"mydiv"> "text" size=50 id="keyword" name="keyword" onkeyup="getMoreContents()" onblur="keywordblur()" onfocus="getMoreContents()"/> "button" value="百度一下" width="50px"/>
"popDiv"> "content_table" bgcolor="#FFFAFA" border="0" cellspacing="0" cellpadding="0"> "content_table_body">

后端代码

package cn.hogan.servlet;

import com.fasterxml.jackson.databind.ObjectMapper;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.invoke.CallSite;
import java.util.ArrayList;
import java.util.List;

@WebServlet("/search")
public class search extends HttpServlet {
    static List list;

    static {
        list = new ArrayList();
        list.add("a");
        list.add("aj");
        list.add("aja");
        list.add("ajax");
        list.add("ba");
        list.add("ajax12");
        list.add("ajax123");
        list.add("ajax1234");
        list.add("ajax12345");
        list.add("ajax123456");
    }


    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 设置编码
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");

        // 获取参数
        String keyword = request.getParameter("keyword");
        if (keyword == null) {
            return;
        }
        ArrayList res = new ArrayList();
        for (String str :list) {
            if (str.contains(keyword)){
                    res.add(str);
            }
        }
        System.out.println(new ObjectMapper().writeValueAsString(res));
        new ObjectMapper().writeValue(response.getWriter(),res);


    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}

  

js+servlet实现百度搜索栏下拉框的实现

标签:button   extends   解析   har   remove   color   width   tps   lsp   

原文地址:https://www.cnblogs.com/hoganhome/p/12590407.html


评论


亲,登录后才可以留言!