struts2跟jquery,json的结合小结
来源:互联网 发布:软件需求说明书模板 编辑:程序博客网 时间:2024/04/29 17:15
struts2 跟jquery,json结合的一个小例子,小结下:
1 页面
<form action="" id="introForm"><label for="name">Enter Your Name</label>
<input name="name">
<input type="submit">
</form>
2 在ACTION部分
public class AjaxActions extends ActionSupport{
private String name;
private String greeting;
private List<string> countryList;
private Map<string,long> countryMap;
public String sayHi(){
greeting="HI " +name;
countryList=new ArrayList();
countryList.add("US");
countryList.add("UK");
countryList.add("Russia");
countryMap= new HashMap();
countryMap.put("US",1L);
countryMap.put("UK",2L);
countryMap.put("Russia",3L);
return ActionSupport.SUCCESS;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getGreeting() {
return greeting;
}
public void setGreeting(String greeting) {
this.greeting = greeting;
}
public List<string> getCountryList() {
return countryList;
}
public void setCountryList(List<string> countryList) {
this.countryList = countryList;
}
public Map<string, long=""> getCountryMap() {
return countryMap;
}
}
3 配置
<struts>
<package extends="struts-default,json-default" name="ajax-package" namespace="/ajax">
<action class="sample.AjaxActions" method="sayHi" name="sayHi">
<result type="json">
</result></action>
</package>
</struts>
4 最后在前端把表单的信息送出,并且把后端的信息简单取出
这里只是通过FIREFOX的CONSOLE输出
,注意这里还演示了如何输出JSON格式的MAP和LIST
$(function(){
$("#introForm").submit(function(){
var formInput=$(this).serialize();
$.getJSON('ajax/sayHi.action', formInput,function(data) {
$('.result').html('' + data.greeting + '
');
$.each(data.countryList,function(index, value){
console.log("value " + value);
});
$.each(data.countryMap,function(key, value){
console.log("key "+ key + ", value " + value);
});
});
return false;
});
1 页面
<form action="" id="introForm"><label for="name">Enter Your Name</label>
<input name="name">
<input type="submit">
</form>
2 在ACTION部分
public class AjaxActions extends ActionSupport{
private String name;
private String greeting;
private List<string> countryList;
private Map<string,long> countryMap;
public String sayHi(){
greeting="HI " +name;
countryList=new ArrayList();
countryList.add("US");
countryList.add("UK");
countryList.add("Russia");
countryMap= new HashMap();
countryMap.put("US",1L);
countryMap.put("UK",2L);
countryMap.put("Russia",3L);
return ActionSupport.SUCCESS;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getGreeting() {
return greeting;
}
public void setGreeting(String greeting) {
this.greeting = greeting;
}
public List<string> getCountryList() {
return countryList;
}
public void setCountryList(List<string> countryList) {
this.countryList = countryList;
}
public Map<string, long=""> getCountryMap() {
return countryMap;
}
}
3 配置
<struts>
<package extends="struts-default,json-default" name="ajax-package" namespace="/ajax">
<action class="sample.AjaxActions" method="sayHi" name="sayHi">
<result type="json">
</result></action>
</package>
</struts>
4 最后在前端把表单的信息送出,并且把后端的信息简单取出
这里只是通过FIREFOX的CONSOLE输出
,注意这里还演示了如何输出JSON格式的MAP和LIST
$(function(){
$("#introForm").submit(function(){
var formInput=$(this).serialize();
$.getJSON('ajax/sayHi.action', formInput,function(data) {
$('.result').html('' + data.greeting + '
');
$.each(data.countryList,function(index, value){
console.log("value " + value);
});
$.each(data.countryMap,function(key, value){
console.log("key "+ key + ", value " + value);
});
});
return false;
});
- struts2跟jquery,json的结合小结
- struts2 跟jquery,json结合的一个小例子
- Struts2+Jquery+ajax+json结合应用
- jquery于json的结合
- struts2 + ajax + json的结合使用
- Struts2结合EasyUI的combobox返回json
- Struts2结合EasyUI的combobox返回json
- JSON与Struts2的结合使用
- jquery autocomplete 与struts2 json插件结合简单例子
- Struts2结合jquery使用Ajax传递Json数据
- SpringMVC层跟JSon结合
- Struts2+JQuery+JSON的集成
- struts2结合jquery的Ajax应用
- Struts2与jQuery框架的结合使用
- jquery, json与ashx的完美结合
- jquery, json与ashx的完美结合
- jquery, json与ashx的完美结合
- jquery, json与ashx的完美结合
- 一个比较好的.net 3.5的异常报告类
- 老外对tomcat 7的一点试用体法
- 介绍一个不错的2.5D的效果的HTML5效果
- mysql中query cache的局限性
- mysql 把所有行的id用逗号串连起来
- struts2跟jquery,json的结合小结
- 介绍9个很有发展潜力的PHP开源项目
- (转)B树的一个很好的小结文
- 在vs.net 2010中使用重构方法
- asp.net 4中的HTML过滤的一个新特性
- 小tips:设置java 的heap
- tomcat的gzip压缩
- jquery判断图片是否完整加载了
- ddos是什么