使用通配符,将配置量降到最低
Struts2还支持class属性和method属性使用来自name属性的通配符。
<a href="<%=context%>/actions/Studentadd">添加学生</a>
<a href="<%=context%>/actions/Studentdelete">删除学生</a>
// 不过,一定要遵守"约定优于配置"的原则
<a href="<%=context%>/actions/Teacher_add">添加老师</a>
<a href="<%=context%>/actions/Teacher_delete">删除老师</a>
<a href="<%=context%>/actions/Course_add">添加课程</a>
<a href="<%=context%>/actions/Course_delete">删除课程</a>
相应的jsp页面有:
Course_add_seccess.jsp
Course_delete_success.jsp
Teacher_add_seccess.jsp
Teacher_delete_success.jsp
Studentadd_success.jsp
Studentdelete_success.jsp
struts.xml中的配置
<action name="Student*" class="action.StudentAction" method="{1}">
<result>/Student{1}_success.jsp</result>
</action>
<action name="*_*" class="action.{1}Action" method="{2}">
<result>/{1}_{2}_success.jsp</result>
</action>
<action name="*_*_*_*" class="action.{1}Action" method="{2}">
<result name="{3}">/${folder}/{4}.jsp</result>
</action>
<!-- name="*"放到最后-->
<action name="*" class="action.UserAction" method="login">
<result name="success">/index.jsp</result>
</action>