Struts2 action中不要将方法以get开头!!!
2016-04-06 21:22
483 查看
Struts2 action中不要将方法以get开头
Struts2 action中不要将方法以get开头
Struts2 action中不要将方法以get开头
重要的事情说三遍!今天调试jquery发送请求到action中我写的三个方法回一次执行。审查代码一点问题都没有
我写的代码如下:
/**
*
*/
package com.artpri.artist.action;
import java.util.List;
import com.opensymphony.xwork2.Action;
/**
*
* @author 王校兵
* @version 1.0, 2016年4月6日
*/
public class GetQueryAlbumPhotoAction extends BaseAction {
private List photoList;// 照片的查询结果集合
private String queryTime;// 要查询照片的拍摄时间条件
private String queryCategory;// 要查询的年代条件
private String queryTitle;// 要查询的标题条件
/**
* 通过相册分类查询相册照片action方法
* @return 页面跳转对应的逻辑代码
* */
public String getPhotoByCategory() {
System.out.println("getPhotoByCategory-------------------------------" + queryCategory);
photoList = getAlbumPhotoMangeService().getPhotoByCategory(queryCategory);
return Action.SUCCESS;
}
/**
* 通过拍摄时间查询相册照片action方法
* @return 页面跳转对应的逻辑代码
* */
public String getPhotoByTime() {
System.out.println("getPhotoByTime-------------------------------" + queryTime);
photoList = getAlbumPhotoMangeService().getPhotoByTime(queryTime);
return Action.SUCCESS;
}
/**
* 通过照片标题查询相册照片action方法
* @return 页面跳转对应的逻辑代码
* */
public String getPhotoByTitle() {
System.out.println("getPhotoByTitle-------------------------------" + queryTitle);
photoList = getAlbumPhotoMangeService().getPhotoByTitle(queryTitle);
return Action.SUCCESS;
}
public List getPhotoList() {
return photoList;
}
public String getQueryCategory() {
return queryCategory;
}
public String getQueryTime() {
return queryTime;
}
public String getQueryTitle() {
return queryTitle;
}
public void setPhotoList(List photoList) {
this.photoList = photoList;
}
public void setQueryCategory(String queryCategory) {
this.queryCategory = queryCategory;
}
public void setQueryTime(String queryTime) {
this.queryTime = queryTime;
}
public void setQueryTitle(String queryTitle) {
this.queryTitle = queryTitle;
}
}
他们会依次执行。因为action中 ajax模式下,调用的action方法不能为get*方式命名,内中机理未知。
于是就把get开头的方法修改了一下,程序就运行正常了,继续找了下原因,最后基本上明白。 个人认为,出现这个问题的原因是因为,action中属性都是以get set方式设置的,这样strut2才能根据反射进行设置,但是当action结束的时候, 就会调用相应的get方法取值,所以导致get开头的method执行了两次。
所以
Struts2 action中不要将方法以get开头
相关文章推荐
- JQuery1——基础($对象,选择器,对象转换)
- JavaScript演示排序算法
- 2015-2016网页设计趋势分析 Web Design of Trends
- jQuery Ajax 跨域调用
- 移动端的长按事件
- jquery教程靠边站,一分钱不花让你免费学会jquery
- JQuery+Strusts1.x无刷新登录
- $.ajax()方法详解
- jQuery ajax - ajax() 方法
- JavaScript 各种遍历方式详解
- 数组方法汇总
- jQuery Html控件基本操作(日常收集整理)
- jQuery插件实现文字无缝向上滚动效果代码
- jQuery菜单插件用法实例
- JQuery 初体验(建议学习jquery)
- 基于Jquery和CSS3制作数字时钟附源码下载(CSS3篇)
- Jquery实现的table最后一行添加样式的代码
- jQuery实现向下滑出的平滑下拉菜单效果
- jQuery 练习[一] 学习jquery的准备工作
- jquery获得页面元素的坐标值实现思路及代码