• jquery-ui-custom autocomplete


     //jsp
    <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
    <%
        String path = request.getContextPath();
        String basePath = request.getScheme() + "://"+ request.getServerName() + ":" + request.getServerPort()+ path + "/";
    %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
        <head>
            <base href="<%=basePath%>">
     
            <title>autocomplete</title>
     
            <meta http-equiv="pragma" content="no-cache">
            <meta http-equiv="cache-control" content="no-cache">
            <meta http-equiv="expires" content="0">
            <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
            <meta http-equiv="description" content="This is my page"> 
      
            <link href="<%=basePath%>js/autocomplete/jquery-ui-1.10.3.custom.css" rel="stylesheet">
            <script src="<%=basePath%>js/jquery-1.7.2.min.js"></script>
            <script src="<%=basePath%>js/autocomplete/jquery-ui-1.10.3.custom.js"></script>
        <script>
            $(function(){
                $( "#autocomplete" ).autocomplete({
                    minLength: 1,//最少输入1个字符才执行
                    source: 'autocomplete.action'
                });
            })
        </script>
        </head>
        <style>
            body {
                font: 62.5% "Trebuchet MS", sans-serif;
                margin: 50px;
            }
        </style>
        <body>
            <h2 style="margin-top: 2em;">
                Autocomplete
            </h2>
            <div>
                <input id="autocomplete" title="type &quot;a&quot;">
            </div>
        </body>
    </html>  
    //struts.xml
    <action name="autocomplete" class="com.test.action.testAction" method="autocomplete"></action> 

    //java
    public String autocomplete() throws Exception{
             
            String[] temp = "align,both,card,dream,error,fail,gson,hello,invaid,job,kill".split(",");
            String name = "[";
            for(int i=0;i<temp.length;i++){
                if(temp[i].indexOf(term)!=-1){
                    name += """+temp[i]+"",";
                }
            }
            if(name.length() > 1)
                name = name.substring(0,name.length()-1);
            name+="]";
             
            System.out.println(name);
             
            HttpServletResponse res = ServletActionContext.getResponse();
            PrintWriter pw = res.getWriter();
            pw.write(name);
            pw.flush();
            pw.close();
             
            return null;
        } 

  • 相关阅读:
    Analysis of Hello2 source code
    CORS’s source, Principle and Implementation
    CDI Features(EL(SPEL),Decorator,Interceptor,Producer)
    Java Design Patterns(2)
    Cookie and Session
    Vue错误信息解决
    cdh搭建仓库
    cdh本地源安装-自用
    创建本地repo源
    dockerfile:python-cuda-nvidia-cudnn
  • 原文地址:https://www.cnblogs.com/holdon521/p/4105784.html
Copyright © 2020-2023  润新知