Struts.xml配置:
<struts>
<constant name="struts.devMode" value="true" />
<package name="actions" namespace="/actions" extends="struts-default">
<!-- method里面的{1}代表Student*后面的第一个*,也就是说如果路径为<%=context %>/actions/Studentadd">的时候,*为add,即调用了add方法 -->
<action name="Student*" class="com.java.action.StudentAction" method="{1}">
<result name="success">
/Student{1}_success.jsp
</result>
</action>
<action name="*_*" class="com.java.action.{1}Action" method="{2}">
<result name="success">
/{1}_{2}_success.jsp
</result>
</action>
</package>
</struts>
JSP调用的路径设置:
<body>
<% String context = request.getContextPath(); %>
使用通配符,将配置量降到最低<br />
<a href="<%=context %>/actions/Studentadd">添加学生</a>
<a href="<%=context %>/actions/Studentdelete">删除学生</a>
<br />
不过,一定要遵守"约定优于配置"的原则
<br />
<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>
</body>