zoukankan      html  css  js  c++  java
  • Struts2_Global_Results_全局结果集

    struts.xml文件配置

     1 <?xml version="1.0" encoding="UTF-8" ?>
     2 <!DOCTYPE struts PUBLIC
     3     "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
     4     "http://struts.apache.org/dtds/struts-2.3.dtd">
     5 
     6 <struts>
     7     <constant name="struts.configuration.xml.reload" value="true"/>
     8     <constant name="struts.enable.DynamicMethodInvocation" value="true"/>
     9     
    10     <package name="default" namespace="/" extends="struts-default">
    11         <default-action-ref name="default"></default-action-ref>
    12         
    13         <global-results>
    14             <result name="mainpage">/mainpage.jsp</result>
    15         </global-results>
    16         
    17         <action name="default">
    18             <result>/default.jsp</result>
    19         </action>
    20         
    21     </package>
    22     
    23     <package name="type" namespace="/type" extends="default">
    24         <action name="index">
    25             <result>/index.jsp</result>
    26         </action>
    27     
    28         <action name="user" class="com.bjsxt.struts2.user.action.UserAction">
    29             <result>/user_success.jsp</result>
    30             <result name="error">/user_error.jsp</result>
    31         </action>
    32     </package>
    33     
    34     <package name="admin" namespace="/admin" extends="default">
    35         <action name="admin" class="com.bjsxt.struts2.user.action.AdminAction">
    36             <result>/admin.jsp</result>
    37         </action>
    38     </package>
    39 </struts>

    UserAction:

    package com.bjsxt.struts2.user.action;
    
    import com.opensymphony.xwork2.ActionSupport;
    
    public class UserAction extends ActionSupport{
        
        private static final long serialVersionUID = -1223017903962609751L;
    
        public Integer type;
        
        public String execute(){
            System.out.println("type = " + this.type);
            if(type == 1) return SUCCESS;
            if(type == 2) return ERROR;
            else return "mainpage";
        }
    
        public Integer getType() {
            return type;
        }
    
        public void setType(Integer type) {
            this.type = type;
        }
    }

    名为 user 的 namespace 中并没有,mainpage的result,它回去找父package中的result,找到了global-result 中的 mainpage

    链接: http://pan.baidu.com/s/1kV4uXON 密码: i96x

  • 相关阅读:
    神经网络学习之----单层感知器
    神经网络学习之----神经网络发展史
    神经网络学习之----神经网络概述
    C语言几种常见的字符串输入
    基于单链表实现集合的交集、并集、差集的运算
    关于单链表的一些基本操作
    输入20个整数存放到一个单向链表中,并顺序逆序输出
    《你的灯亮着吗》阅读笔记
    场景调研
    站立会议总结09
  • 原文地址:https://www.cnblogs.com/ShawnYang/p/6674596.html
Copyright © 2011-2022 走看看