ITeye博客

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

cakin24 · 2017-10-21 07:40 · Struts · 编程语言 · Markdown

一 配置方法


 

 

二 代码

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";

        }

}

 

三 测试

 

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。