这个问题研究了一天,还是因为配置的时候没有认真,一不小心,酿成了大错。当发现的时候感觉好尴尬啊::>_<::
CostAction:
package com.tenni.action; import java.util.List; import javax.annotation.Resource; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Controller; import com.tenni.dao.ICostDao; import com.tenni.entity.Cost; @Controller @Scope("prototype") public class CostAction { @Resource private ICostDao costDao; //input private int page = 1; private int pageSize; //output private String msg; private List<Cost> list; private int totalPage; public String findAll(){ list = costDao.findAll(); return "success"; } //分页查询 public String load(){ list = costDao.findByPage(page, pageSize); totalPage = costDao.findTotalPage(pageSize); return "success"; } /** * @return the msg */ public String getMsg() { return msg; } /** * @param msg the msg to set */ public void setMsg(String msg) { this.msg = msg; } /** * @return the list */ public List<Cost> getList() { return list; } /** * @param list the list to set */ public void setList(List<Cost> list) { this.list = list; } public ICostDao getCostDao() { return costDao; } public void setCostDao(ICostDao costDao) { this.costDao = costDao; } public int getPage() { return page; } public void setPage(int page) { this.page = page; } public int getPageSize() { return pageSize; } public void setPageSize(int pageSize) { this.pageSize = pageSize; } public int getTotalPage() { return totalPage; } public void setTotalPage(int totalPage) { this.totalPage = totalPage; } }
Struts.xml
<!-- 公共的包,封装了通用的拦截器、通用的result --> <package name="interceptor" extends="json-default"> <interceptors> <!-- 登录检查拦截器 --> <interceptor name="loginInterceptor" class="com.tenni.interceptor.LoginInterceptor" /> <!-- 保持session开启拦截器 --> <interceptor name="openSessionInterceptor" class="com.tenni.interceptor.OpenSessionInViewInterceptor" /> <!-- 登录检查拦截器栈 --> <interceptor-stack name="loginStack"> <interceptor-ref name="loginInterceptor" /> <interceptor-ref name="openSessionInterceptor" /> <!-- 不要丢掉默认的拦截器栈,里面有很多Struts2依赖的拦截器 --> <interceptor-ref name="defaultStack" /> </interceptor-stack> </interceptors> <!-- 设置action默认引用的拦截器 --> <default-interceptor-ref name="loginStack" /> <!-- 全局的result,包下所有的action都可以共用 --> <global-results> <!-- 跳转到登录页面的result --> <result name="toLogin" type="redirectAction"> <param name="namespace">/login</param> <param name="actionName">toLogin</param> </result> <result name="error" type="redirectAction"> <param name="namespace">/error</param> <param name="actionName">error</param> </result> </global-results> </package> <!-- cost action --> <package name="cost" namespace="/cost" extends="interceptor"> <action name="findAll" class="costAction" method="findAll"> <result name="success"> /WEB-INF/main/cost.jsp </result> </action> <action name="findCost" class="costAction" method="load"> <!-- 注入页容量 --> <param name="pageSize">3</param> <result name="success"> /WEB-INF/main/find_cost.jsp </result> </action> </package>
package----->cost extends---->interceptor(继承了json)
由于使用Spring来管理Action,因此需要通过Spring容器来创建Action,因此class属性指定的是组件的ID。
所以:
<action name="findAll" class="costAction"中---> costAction 不能写成com.tenni.action.CostAction