(一)直接调用方法(不推荐使用)

1Action类:

private String savePath;

	public String getSavePath() {
		return savePath;
	}

	public void setSavePath(String savePath) {
		this.savePath = savePath;
	}

	public String other() {
		savePath = "other";
		return "success";
	}

	public String execute() {
		savePath = "execute";
		return "success";
}

2struts.xml文件的配置:

<struts>
	<package name="package" namespace="/test" 
  extends="struts-default">
		<action name="emp" class="struts.employeeAction" 
  method="execute">
			<result name="success">/index.jsp</result>
		</action>
	</package>
</struts>

当输入:http://localhost:8080/Struts_3/test/emp.action

时会输出:execute 即调用execute()方法;

当输入:http://localhost:8080/Struts_3/test/emp!other.action

时会输出:other 即调用other()方法。

(二)使用通配符(推荐使用)

1)Aciton类与(一)中的同样

2)struts.xml文件的配置:

<struts>
	<package name="package" namespace="/test" 			
  extends="struts-default">
		<action name="emp*" class="struts.employeeAction" 
  method="{1}">
			<result name="success">/index.jsp</result>
		</action>
	</package>
</struts>

訪问路径:http://localhost:8080/Struts_3/test/empexecute

这时会输出:execute 即调用execute()方法;

訪问路径:http://localhost:8080/Struts_3/test/empother

这时会输出:other 即调用other()方法。