struts.xml文件:
<struts>
<constant name="struts.devMode" value="true" />
<package name="user" extends="struts-default" namespace="/user">
<!--第一种方法-->
<action name="userAdd" class="com.bjsxt.struts2.user.action.UserAction" method="add">
<result>/user_add_success.jsp</result> </action> <!--第二种方法--> <action name="user" class="com.bjsxt.struts2.user.action.UserAction"> <result>/user_add_success.jsp</result> </action> </package></struts>
jsp文件:
<body>
<a href="<%=context %>/user/userAdd">添加用户</a><br /><!--第一种方法--><a href="<%=context %>/user/user!add">添加用户</a><br /><!--第二种方法--></body>总结:
(1)Action执行的时候并不一定要执行execute方法,可以在配置文件中配置Action的时候用method=来指定执行哪个方法,
(2)也可以在url地址中动态指定(动态方法调用DMI)(推荐)前者会产生太多的action,所以不推荐使用
感觉比servlet要简单和方便许多,可以提高效率。但是地址问题还是经常出错。百度上使用绝对地址,尽量少使用相对地址。