关于struts1.3中使用DispatchAction的一个问题

在action中 不能有execute方法,否则其他的方法则不能执行.

如下:

package com.yanek.mvc.demo;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

public class TestAction extends DispatchAction
{

public ActionForward execute(ActionMapping mapping, ActionForm actionform,
HttpServletRequest request, HttpServletResponse response)
throws Exception {

UserForm form=(UserForm)actionform;

String username=form.getUsername();
String password=form.getPassword();

System.out.println("parametor..."+mapping.getParameter());

System.out.println("username..."+username);
System.out.println("password..."+password);


if (username.equals("admin") && password.equals("admin"))
{
mapping.findForward("success");
}
else
{
mapping.findForward("success");
}



System.out.println("action execue index...");
return mapping.findForward("success");

}

public ActionForward add(ActionMapping mapping, ActionForm actionform,
HttpServletRequest request, HttpServletResponse response)
throws Exception {

UserForm form=(UserForm)actionform;

String username=form.getUsername();
String password=form.getPassword();

System.out.println("username..."+username);
System.out.println("password..."+password);

System.out.println("action add ...");

return mapping.findForward("add");

}

public ActionForward update(ActionMapping mapping, ActionForm actionform,
HttpServletRequest request, HttpServletResponse response)
throws Exception {

UserForm form=(UserForm)actionform;

String username=form.getUsername();
String password=form.getPassword();

System.out.println("username..."+username);
System.out.println("password..."+password);

System.out.println("action update ...");

return mapping.findForward("update");

}


public ActionForward delete(ActionMapping mapping, ActionForm actionform,
HttpServletRequest request, HttpServletResponse response)
throws Exception {

UserForm form=(UserForm)actionform;

String username=form.getUsername();
String password=form.getPassword();

System.out.println("username..."+username);
System.out.println("password..."+password);

System.out.println("action delete ...");

return mapping.findForward("delete");

}

public ActionForward list(ActionMapping mapping, ActionForm actionform,
HttpServletRequest request, HttpServletResponse response)
throws Exception {

UserForm form=(UserForm)actionform;

String username=form.getUsername();
String password=form.getPassword();

System.out.println("username..."+username);
System.out.println("password..."+password);

System.out.println("action list ...");

return mapping.findForward("list");

}

}

由于 action里有execute方法,所以其他的方法都不能执行,执行其他方法时都会执行execute方法.

把execute改名或去掉即可.

配置:

<action path="/test" type="com.yanek.mvc.demo.TestAction" name="userForm" scope="request" parameter="action">
<forward name="success" path="/test/index.jsp"/>
<forward name="add" path="/test/add.jsp"/>
<forward name="update" path="/test/update.jsp"/>
<forward name="delete" path="/test/delete.jsp"/>
<forward name="list" path="/test/list.jsp"/>

</action>

访问:

http://127.0.0.1:8080/struts1Demo/test.do?action=list

http://127.0.0.1:8080/struts1Demo/test.do?action=add

http://127.0.0.1:8080/struts1Demo/test.do?action=update

http://127.0.0.1:8080/struts1Demo/test.do?action=delete

执行相应的方法

如果有execute方法,则执行如上方法都会进入execute方法.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值