有两种方法:
一 动态方法调用
如果Action中存在多个方法时,我们可以使用!+方法名调用指定方法。如下:
public class HelloWorldAction{
private String message;
....
public String execute() throws Exception{
this.message = "我的第一个struts2应用";
return "success";
}
public String other() throws Exception{
this.message = "第二个方法";
return "success";
}
}
假设访问上面action的URL路径为: /struts/test/helloworld.action
要访问action的other() 方法,我们可以这样调用:
/struts/test/helloworld!other.action
如果不想使用动态方法调用,我们可以通过常量struts.enable.DynamicMethodInvocation关闭动态方法调用。
<constant name="struts.enable.DynamicMethodInvocation" value="false"/>
二 使用通配符定义action
<package name="itcast" namespace="/test" extends="struts-default">
<action name="helloworld_*" class="cn.itcast.action.HelloWorldAction" method="{1}">
<result name="success">/WEB-INF/page/hello.jsp</result>
</action>
</package>
public class HelloWorldAction{
private String message;
....
public String execute() throws Exception{
this.message = "我的第一个struts2应用";
return "success";
}
public String other() throws Exception{
this.message = "第二个方法";
return "success";
}
}
要访问other()方法,可以通过这样的URL访问:/test/helloworld_other.action
分享到:
相关推荐
Struts1中怎样实现DispatchAction配置多个input属性\Struts1中怎样实现DispatchAction配置多个input属性
一个比较简单的struts的dispatchAction 类的入门案例,适合初学者理解dispatchAction
用struts1.2写的一个计算器示例程序,供研究struts原理的初学者参考,其中action继承的DispatchAction。
简单的DispatchAction实例。。。。。。。。
Struts(DispatchAction) + 存储过程 => 实现分页效果
自习struts时做时,大家可以互相交流一下
解决Struts1.x中使用Validator框架对DispatchAction不同方法使用不同的字段验证 你可以先参看我的blog文章:http://blog.csdn.net/qjyong/archive/2008/11/16/3311688.aspx 再决定是否下载。
利用struts标签,dispatchAction,实现增删改查 有利于初学者掌握struts!
4.9. struts中怎么配置form-bean、action、tiles 10 4.10. logic标签有哪几个? 12 4.11. action是单实例还是多实例,为什么? 13 4.12. dispatchAction是用什么技术实现的? 13 4.13. struts2.0的mvc模式?与struts...
03Struts2常用标签&DispatchAction.rar03Struts2常用标签&DispatchAction.rar03Struts2常用标签&DispatchAction.rar03Struts2常用标签&DispatchAction.rar
Struts 之 DispatchAction add
在页面中用js传递执行方法参数,传递到后台执行, 在你用的Action类中的方法名前加“run“及可被调用。
struts中的DispatchAction应用实例
struts1.2 图片文件上传(单个/动态多个) 单个的采用通用Action 需要ActionForm的,而动态多个上传是采用动态代理类(DispatchAction) 希望对大家有用,另JSP在IE测试通过,JS我就不再处理了!
struts 实现ajax效果,里面包含了很多技术,jsp的filter,各种struts标签和DispatchAction,js代码丰富,可用通用.... 个人提倡资源共享,大家随便下,^_^....
import org.apache.struts.action.ActionForm;import org.apache.struts.action.ActionForward;import org.apache.struts.action.ActionMapping;import org.apache.struts.actions.DispatchAction等缺少
最近自学java中的框架-struts写了一些小例子,这都是很经典的程序,如果大家瞧得起要下载去看看,顺便给俺找找不足的地方。我的qq 821865130 email qingtian_hechen@163.com 希望大家能多多给我帮助。在此谢谢各位!...
05 Struts_05DynaActionForm : 相对应ActionForm来说,动态ActionForm只需要在配置文件中配置就可以了,但是它不能实现验证功能,演示人机交互实例。 06 Struts_06Filter : 中文编码的统一处理,通过Struct的请求...
12.6 整合Struts、Spring和Hibernate实现用户管理 12.6.1 Struts、Spring和Hibernate的整合方式 12.6.2 编写用户注册画面regedit.jsp 12.6.3 编写用户登录画面login.jsp 12.6.4 编写注册控制器RegeditAction.java ...
主要介绍了深入解析Java的Struts框架中的控制器DispatchAction,Struts是Java的SSH三大web开发框架之一,需要的朋友可以参考下