使用通配符方式配置Struts2

第一步:在web.xml中配置核心过滤器:

1 <filter>
2     <filter-name>struts2</filter-name>
3     <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
4   </filter>
5   <filter-mapping>
6     <filter-name>struts2</filter-name>
7     <url-pattern>/*</url-pattern>
8   </filter-mapping>

第二步编制struts2_Action类:

 1 public class UserAction extends ActionSupport{
 2         /**
 3          * 
 4          */
 5         private static final long serialVersionUID = 1L;
 6         public String login() throws Exception {
 7             System.out.println("执行了login方法");
 8             return SUCCESS;
 9         }
10         public String regist() throws Exception {
11             System.out.println("执行了regist方法");
12             return SUCCESS;
13         }
14     }

第三步配置struts.xml

1 <package name="demo" extends="struts-default" namespace="/">
2        <action name="user_*" class="com.igeek_01_mehtod.UserAction" method="{1}">
3             <result name="success">
4                 /{1}Result.jsp
5             </result>
6     </action>  
7 </package>

猜你喜欢

转载自www.cnblogs.com/yuanqisheng/p/12517185.html
今日推荐