问题描述:
struts-config.xml配置
<action attribute="itemForm" input="/jsp/errors.jsp" name="itemForm" parameter="status" path="/jsp/ques/item" scope="request" type="com.klx.struts.action.ItemAction"> <forward name="question" path="/jsp/ques/question.jsp"></forward> </action>
itemAction.java代码
public class ItemAction extends DispatchAction {
private IItemDAO iitemdao;
/**
* Method execute
*
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
*/
public ActionForward selectAll(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
List all = null;
try{
all = this.iitemdao.queryAll();
}catch(Exception e){
e.printStackTrace();
}
request.setAttribute("all", all);
return mapping.findForward("question");
}
public ActionForward aa(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
ItemForm itemForm = (ItemForm) form;// TODO Auto-generated method stub
return null;
}
public IItemDAO getIitemdao() {
return iitemdao;
}
public void setIitemdao(IItemDAO iitemdao) {
this.iitemdao = iitemdao;
}
调用:http://localhost:8080/myznt/jsp/ques/item.do?status=selectAll
问题:如果按以上方式调用,则会转向执行itemAction类的execute()方法,selectAll方法不会执行(不知道为什么?还请大家指点),因为action默认总是执行execute()方法.
解决方式:如果想执行selectAll,有两种方法
1、在execute()方法中调用selectAll(),把值返回
2、不要写execute()方法,或更成其它名称,程序就可以执行selectAll();