读书人

运用通配符定义action

发布时间: 2012-09-09 09:27:54 作者: rapoo

使用通配符定义action
<package name="itcast" namespace="/test" extends="struts-default">
<action name="helloworld_*"
<!--helloworld_* 其中_*表示匹配后面的{1}中的参数 -->
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

读书人网 >Web前端

热点推荐