jQuery.Autocomplete与struts2的整合

您所在的位置:网站首页 哪些花比较好看图片大全 jQuery.Autocomplete与struts2的整合

jQuery.Autocomplete与struts2的整合

#jQuery.Autocomplete与struts2的整合| 来源: 网络整理| 查看: 265

jQuery.Autocomplete与struts2的整合 原创

咔咔是咖咖 2023-05-08 13:30:43 ©著作权

文章标签 java json ajax 文章分类 Java 后端开发

©著作权归作者所有:来自51CTO博客作者咔咔是咖咖的原创作品,请联系作者获取转载授权,否则将追究法律责任

ssh中jquery autocomplete使用示例

jQuery.Autocomplete与struts2的整合

 

以下是我的实践,不过不知道为什么autocomplete功能不能从返回的json对象中选择包含输入字段的一项,例如source:person!ajaxSelectPerson ,这个时候person! ajaxSelectPerson返回的json,当输入wang时

jQuery.Autocomplete与struts2的整合_ajax

,当source: ["张三","李斯","王五","赵六","黑龙","白海","湘伦"]时

jQuery.Autocomplete与struts2的整合_java_02

 

package com.maple.action; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Date; import java.util.List; import net.sf.json.JSONArray; import org.apache.struts2.ServletActionContext; import org.apache.struts2.convention.annotation.ResultPath; import com.opensymphony.xwork2.ActionSupport; @ResultPath("/") // @Results({@Result(name="")}) public class PersonAction extends ActionSupport{ public String result; public String getResult() { return result; } public void setResult(String result) { this.result = result; } public String autocom() { result="[\"zhangsan\",\"lisi\",\"wangwu\",\"zhangsan\",\"sun\",\"zhouw\",\"hello\",\"world\",\"nihsi\"]"; return "autocom"; } public String ajaxSelectPerson(){ try { String search = ServletActionContext.getRequest().getParameter("term"); System.out.println(search); // if(search==null||search.length()==0) return null; List names = new ArrayList(); names.add("zhangsan"); names.add("lisi"); names.add("wangwu"); names.add("zhangsan"); names.add("sun"); names.add("zhouw"); names.add("hello"); names.add("world"); names.add("nihsi"); ServletActionContext.getResponse().setCharacterEncoding("UTF-8"); JSONArray json = JSONArray.fromObject(names); PrintWriter out = ServletActionContext.getResponse().getWriter(); out.print(json.toString()); System.out.println( new Date()+" "+json); out.flush(); out.close(); return null; } catch (Exception e) { e.printStackTrace(); } return null; } } < html > < head > < base href ="" > < link rel ="stylesheet" href ="development-bundle/themes/base/jquery.ui.all.css" /> < style > .ui-autocomplete { max-height: 100px; overflow-y: auto; /* prevent horizontal scrollbar */ overflow-x: hidden; } .ui-autocomplete { height: 100px; } < script src ="js/jquery-1.8.2.min.js" > < script src ="js/jquery-ui-1.8.24.custom.min.js" > < script > source:"hello-world!returnData" $( function() { var availableTags = [${theData} ]; $( "#tags" ).autocomplete({ source: ["张三","李斯","王五","赵六","黑龙","白海","湘伦"] // "person!ajaxSelectPerson",// }); /**/ }); < body > < div class ="ui-widget" > < label for ="tags" >Tags: < input id ="tags" />

 

收藏 评论 分享 举报

上一篇:struts2文件下载

下一篇:SSH Secure Shell Client 记住密码



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3