指定多个配置文件-深入Struts2

一 配置方法


 
 
二 代码
1、helloworld.xml
<? xml version = "1.0" encoding = "UTF-8" ?>
<! DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" " http://struts.apache.org/dtds/struts-2.1.dtd" ; >
< struts >
         < package name = "default" namespace = "/" extends = "struts-default" >
                 < action name = "*_*_*" method = "{2}" class = "com.cakin.{3}.{1}Action" >
                         < result > /result.jsp </ result >
                         < result name = "add" > /{2}. jsp </ result >
                         < result name = "update" > /{2}. jsp </ result >
                 </ action >
         </ package >
</ struts >
2、 struts.xml
<? xml version = "1.0" encoding = "UTF-8" ?>
<! DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" " http://struts.apache.org/dtds/struts-2.1.dtd" ; >
< struts >
         < include file = "helloworld.xml" ></ include >
        
         < constant name = "struts.enable.DynamicMethodInvocation" value = "false" ></ constant >
</ struts >
3、Action类
package com.cakin.action;
 
import com.opensymphony.xwork2.ActionSupport;
 
public class HelloWorldAction extends ActionSupport {
         @Override
         public String execute() throws Exception {
                System. out .println( "执行Action" );
                 return SUCCESS ;
        }
        
         public String add()
        {
                 return "add" ;
        }
        
         public String update()
        {
                 return "update" ;
        }
}
 
三 测试


 

猜你喜欢

转载自cakin24.iteye.com/blog/2397139
今日推荐