struts.xml文件配置

 <?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd"> <struts>
<constant name="struts.configuration.xml.reload" value="true"/>
<constant name="struts.enable.DynamicMethodInvocation" value="true"/> <package name="default" namespace="/" extends="struts-default">
<default-action-ref name="default"></default-action-ref> <global-results>
<result name="mainpage">/mainpage.jsp</result>
</global-results> <action name="default">
<result>/default.jsp</result>
</action> </package> <package name="type" namespace="/type" extends="default">
<action name="index">
<result>/index.jsp</result>
</action> <action name="user" class="com.bjsxt.struts2.user.action.UserAction">
<result>/user_success.jsp</result>
<result name="error">/user_error.jsp</result>
</action>
</package> <package name="admin" namespace="/admin" extends="default">
<action name="admin" class="com.bjsxt.struts2.user.action.AdminAction">
<result>/admin.jsp</result>
</action>
</package>
</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

Struts2_Global_Results_全局结果集的更多相关文章

  1. crm创建和编辑全局选项集

    一个选项集就是可包含在一个实体中的某种类型的字段.它定义一组选项.当一个选项集显示在窗口中时,将使用下拉列表控件.当在 Advanced Find 中显示时,则使用选择列表控件.有时,开发者将选项集称 ...

  2. 全局结果集,带参数的结果集和动态结果集(struts2)

    全局结果集: 当许多action都有共同的结果时,如果每个package都存在一个相同结果,会使得struts.xml比较臃肿,所以使用全局的结果集.一个包内的全局结果集可以通过包的继承而被其它包使用 ...

  3. struts中json机制与普通页面跳转机制混用(全局结果集配置返回json)

    package继承json-default与struts-default 返回结果是add的话将addResult属性转换为json返回(addResult属性有getter,setter方法),返回 ...

  4. struts xml中的result的类型、全局结果集、异常mapping、继承

    例子: <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC     ...

  5. Struts2 全局结果集-全局result节点设置,package设置abstract=true的实现

    转自:https://blog.csdn.net/u013161278/article/details/41855273 如果我们所有的action均有可能跳到相同的页面,则不妨使用全局result. ...

  6. Struts2--Global Result全局结果集

    如果有很多action,有共同的result指向, 而且属于不同的包,那么可以继承上面的包, 然后写一个<global-results> 1. jsp显示文件: <ol> &l ...

  7. Struts2 全局结果集

    1.index,jsp <body> Result类型 <ol> <li><a href="user/user?type=1">返回 ...

  8. Struts2学习---result结果集

    这一章节主要介绍如何配置结果集,分为以下几个知识点: 结果集类型(result type) 全局结果集(global types) 动态结果集(dynamic type) 带有参数的结果集(type ...

  9. 3、基于多播、安全认证的corosync集群(VIP、Httpd、Filesystem)

    Messaging Layer --> CRM --> RA systemd:/usr/lib/systemd/system     systemd有一个特性,即便一个服务开机启动,但是在 ...

随机推荐

  1. 安装maven时遇到的问题

    配置好环境变量和本地仓库后,在命令行里输入mvn compile,可以显示成功,但是mvn install后就一直失败.显示如下错误: 在idea中显示如下错误: 其实即使显示编译成功,但并没有真正的 ...

  2. 用rc.local工具开机自启动

    对于一些程序来说,无法直接开机自启动.那么我们可以利用开机自启动来执行一些命令,达到开机自启动的效果!!! 下面用tomcat来举个例子 tomcat启动的命令一般是./startup.sh 那么我们 ...

  3. 6.动态sql - if

    满足条件的数据 mapper.xml 满足if条件就执行,不满足就不加 <select id="selectStateByTitle" parameterType=" ...

  4. [Groovy]Parse properties file in Groovy

    def props = new Properties() new File("foo.properties").withInputStream { s -> props.lo ...

  5. 使用lombok 简化代码

    第一步:添加依赖 第二步:下载 lombok  jar 包 第三步 :打开cmd 命令行 执行命令, -javaagent:lombok.jar -Xbootclasspath/a:lombok.ja ...

  6. Github如何在Linux系统下创建本地仓库

    一.电脑上安装 Git Ubuntu安装GIt:  apt-get install git 查看版本信息:    git version 配置Git用户信息  输入: git config --glo ...

  7. Applese 涂颜色(python解法)

    链接:https://ac.nowcoder.com/acm/contest/330/E 来源:牛客网 题目描述 精通程序设计的 Applese 叕写了一个游戏. 在这个游戏中,有一个 n 行 m 列 ...

  8. Nginx静态服务,域名解析

    安装这里就不写了在LNMP里有具体的安装 1.1 常用来提供静态Web服务的软件有如下三种:     Apache:这是中小型Web服务的主流,Web服务器中的老大哥.     Nginx:大型网 ...

  9. esper(4-1)-简单context

    1.创建context语法 create context context_name partition [by] event_property [and event_property [and ... ...

  10. VMware硬盘空间——扩容

    VMware原来分配的硬盘空间太小了--扩容 找到VMware的安装路径,如我是默认安装的:C:\Program Files (x86)\VMware\VMware Workstation,打开该路径 ...