struts2+json取list报错,帮我看看
页面加载的时候执行:
findAll.action
struts.xml code:
<include file="struts-default.xml"></include>
<package name="struts" extends="struts-default" >
<action name="HelloWorld" class="com.test.action.HelloWorldAction" >
<result name="success">/HelloWorld.jsp</result>
</action>
</package>
<package name="json" extends="json-default">
<action name="findAll" class="com.test.action.ListAction" method="findAll">
<result type="json">
<param name="root">page</param>
<param name="excludeProperties">totalProperty,conditions,limit,start,success,objCondition</param>
</result>
</action>
</package>
ListAction code :
public class ListAction extends BaseAction {
private Page page;
private Duty duty;
private Integer dutyId;
private boolean success;
public String findAll() {
DutyDAO dao = new DutyDAO();
page = new Page();
page.setRoot(dao.findAll());
return SUCCESS;
}
public Page getPage() {
return page;
}
public void setPage(Page page) {
this.page = page;
}
public Duty getDuty() {
return duty;
}
public void setDuty(Duty duty) {
this.duty = duty;
}
public Integer getDutyId() {
return dutyId;
}
public void setDutyId(Integer dutyId) {
this.dutyId = dutyId;
}
public boolean isSuccess() {
return success;
}
public void setSuccess(boolean success) {
this.success = success;
}
}
dao code:
public List<Duty> findAll() {
List<Duty> list = new ArrayList<Duty>();
try {
conn = DataSourceFactory.getDataSource().getConnection();
String sql = "select * from duty";
PreparedStatement pstmt = conn.prepareStatement(sql);
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
Duty duty = new Duty();
duty.setDutyId(rs.getInt("dutyId"));
duty.setDutyName(rs.getString("dutyName"));
duty.setRemark(rs.getString("remark"));
list.add(duty);
}
} catch (
SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
if (!conn.isClosed() || conn != null) {
conn.close();
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return list;
}
------解决方案--------------------
可能是版本不对应的关系。
0.33的json-plugin对应struts2.1.x,而0.32对应2.0.x
看看