Struts2--Global Result全局结果集
如果有很多action,有共同的result指向, 而且属于不同的包,那么可以继承上面的包, 然后写一个<global-results>
1. jsp显示文件:
<ol>
<li><a href="user/user?type=1">返回success</a></li>
<li><a href="user/user?type=2">返回error</a></li>
<li><a href="user/user?type=3">返回global result</a></li>
<li><a href="admin/admin">admin,继承user包</a></li>
</ol>
2. struts.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.devMode" value="true" />
<package name="user" namespace="/user" extends="struts-default">
<global-results>
<result name="mainpage">/main.jsp</result>
</global-results> <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="user">
<action name="admin" class="com.bjsxt.struts2.user.action.AdminAction">
<result>/admin.jsp</result>
</action>
</package>
</struts>
userAction.JAVA:
package com.bjsxt.struts2.user.action; import com.opensymphony.xwork2.ActionSupport; public class UserAction extends ActionSupport {
private int type;
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
@Override
public String execute() throws Exception {
if(type == 1) return "success";
else if (type == 2) return "error";
else return "mainpage";
}
}
adminAction.java:
package com.bjsxt.struts2.user.action; import com.opensymphony.xwork2.ActionSupport; public class AdminAction extends ActionSupport { @Override
public String execute() throws Exception {
return "mainpage";
} }
Struts2--Global Result全局结果集的更多相关文章
- 04. struts2中Result配置的各种视图转发类型
概述 <action name="helloworld" class="com.liuyong666.action.HelloWorldAction"&g ...
- Struts2学习---result结果集
这一章节主要介绍如何配置结果集,分为以下几个知识点: 结果集类型(result type) 全局结果集(global types) 动态结果集(dynamic type) 带有参数的结果集(type ...
- 全局结果集,带参数的结果集和动态结果集(struts2)
全局结果集: 当许多action都有共同的结果时,如果每个package都存在一个相同结果,会使得struts.xml比较臃肿,所以使用全局的结果集.一个包内的全局结果集可以通过包的继承而被其它包使用 ...
- Struts2 全局结果集
1.index,jsp <body> Result类型 <ol> <li><a href="user/user?type=1">返回 ...
- Struts2 语法--result type
result type: dispatcher,redirect:只能跳转到jsp,html之类的页面,dispatcher属于服务器跳转, redirect属于客户端跳转 chain: 等同于for ...
- Struts2配置Result(Struts2_result)
一.概要 二.常用四种类型的配置 Struts.xml <?xml version="1.0" encoding="UTF-8" ?> <!D ...
- Struts2之Result详解
上一篇我们把Struts2中的Action接收参数的内容为大家介绍了,本篇我们就一起来简单学习一下Action的4种Result type类型,分为:dispatcher(服务端页面跳转):redir ...
- struts中json机制与普通页面跳转机制混用(全局结果集配置返回json)
package继承json-default与struts-default 返回结果是add的话将addResult属性转换为json返回(addResult属性有getter,setter方法),返回 ...
- struts2的result的类型配置简介
一.在strut2的action处理完成后,就应该向用户返回结果信息result 根据以下代码作为实例分析: <package name="Hello" extends=&q ...
随机推荐
- 把aspx页面输出成xml的方法注意事项
先贴代码 Response.Charset = "gb2312"; Response.ContentType = "text/xml"; Response.Co ...
- Spring Security教程
原文地址:http://blog.csdn.net/jaune161/article/details/17640071 http://blog.csdn.net/jaune161/article/de ...
- Java中判断字符串中相同字符的个数
public static int countStr(String str1, String str2) { int counter=0; if (str1.indexOf(str2) == -1) ...
- 脚本添加crontab任务【转】
今天朋友问,计划任务是用crontab -e来添加的,如何使用脚本来添加呢? 在执行crontab -e命令时,会在/var/spool/cron目录下创建一个文件,文件的名称是你当前的用户名,内容就 ...
- viewpager处理(三):让viewpager不预加载下一页
有时候viewpager加载页面的时候,我们发现页面的数据量很大,预加载的话会消耗性能,为了节省用户流量和手机性能,所以我们想让viewpager不自动预加载下一页,怎么实现呢? viewpager预 ...
- python http请求
from httplib2 import Http def postDada(): http=Http() heads={"pragma":"no-cache" ...
- listctrl中的cell如何支持被复制
为了方便测试data pipeline, 使用wxpython开发了一个小工具,用来显示csv文档中的特定列,及数据库中的指定值. 显示数据的contrl选择了listctrl.但这里有个问题,显示的 ...
- VS2008 安装后没有模板
VS2008 安装过程没有任何报错 启动VS2008,新建项目时就成了这样,没有任何模板: 解决方法: 开始 –> 程序 –> Microsoft Visual Studio 2008– ...
- HTML+CSS Day05 基本CSS选择器、复合CSS选择器与CSS继承性
1.基本CSS选择器 (1)标记选择器 <style> h1{ color:red; font-size:25px;} &l ...
- IDA_Python命令行使用
Python>import idaapi Python>hex(idaapi.get_first_cref_from(here()))