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

阅读更多
一 配置方法

指定多个配置文件-深入Struts2_第1张图片
 
 
二 代码
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" ;
        }
}
 
三 测试

 


指定多个配置文件-深入Struts2_第2张图片
 
  • 指定多个配置文件-深入Struts2_第3张图片
  • 大小: 69.4 KB
  • 指定多个配置文件-深入Struts2_第4张图片
  • 大小: 19.6 KB
  • 查看图片附件

你可能感兴趣的:(配置文件)