Specifying Multiple Configuration Files - Diving into Struts2

A configuration method


 
 
two code
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 class
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" ;
        }
}
 
Three tests

 



 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326839196&siteId=291194637