【web开发学习笔记】Structs2 Result学习笔记(一)简介
Structs2 Result学习笔记(一)简介
问题一
<struts>
<constant name="struts.devMode" value="true" />
<package name="resultTypes" namespace="/r" extends="struts-default">
<action name="r1">
<result type="dispatcher">/r1.jsp</result>
</action> <action name="r2">
<result type="redirect">/r2.jsp</result>
</action> <action name="r3">
<result type="chain">r1</result>
</action> <action name="r4">
<result type="redirectAction">r2</result>
</action> </package>
</struts>
dispatcher - forward运用server跳转 server跳转 显示action
redirect - 重定向
跳转到jsp
chain
server跳转
redirectAction
问题二
chain跳转 -> 从一个action,跳转至另外一个包里面的action的方法:
<package name="public" extends="struts-default">
<!-- Chain creatAccount to login, using the default parameter -->
<action name="createAccount" class="...">
<result type="chain">login</result>
</action> <action name="login" class="...">
<!-- Chain to another namespace -->
<result type="chain">
<param name="actionName">dashboard</param>
<param name="namespace">/secure</param>
</result>
</action>
</package> <package name="secure" extends="struts-default" namespace="/secure">
<action name="dashboard" class="...">
<result>dashboard.jsp</result>
</action>
</package>
通过样例能够看出,是通过为chain配置actionName參数和namespace參数。
详细实例參见struts-2.1.6/docs/docs/chain-result.html里面的文档说明。
问题三。全局Result
//前端htm
<body>
Result类型
<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>
</body>
//struct.xml
<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.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.struts2.user.action.AdminAction">
<result>/admin.jsp</result>
</action>
</package>
</struts>
//类包
//AdminAction
package com.struts2.user.action;
import com.opensymphony.xwork2.ActionSupport;
public class AdminAction extends ActionSupport { @Override
public String execute() throws Exception {
return "mainpage";
}
} //UserAction
package com.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";
}
}
分析1
<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.struts2.user.action.UserAction">
<result>/user_success.jsp</result>
<result name="error">/user_error.jsp</result>
</action>
</package>
这段配置文件里,result 为success时。调用user_success.jsp,result为error时,调用
/user_error.jsp。其余全部的情况都使用result为mainpage的配置。能够共用这个结果集。
分析二
<package name="admin" namespace="/admin" extends="user">
<action name="admin" class="com.struts2.user.action.AdminAction">
<result>/admin.jsp</result>
</action>
</package>
extends的作用是从另外一个包里面继承配置信息,工作中使用对项目进行分模块处理,每一个模块都有公共的配置信息,这样能够将公共配置信息定义为<global-results>。然后被各个模块继承,简化处理。和c++/java中的继承关系好像啊!
问题四:struct-default解析
源文件在ReferencedLibraries/WebRoot/WEB-INF/lib/struts2-core-2.1.6.jar/struct-default.xml
<package name="struts-default" abstract="true">
默认定义了拦截器
<default-interceptor-ref name="defaultStack"/>
<default-class-ref class="com.opensymphony.xwork2.ActionSupport" />
结论:配置非常复杂,使用不需改。
【web开发学习笔记】Structs2 Result学习笔记(一)简介的更多相关文章
- 【web开发学习笔记】Structs2 Result学习笔记(三)带參数的结果集
Result学习笔记(三)带參数的结果集 第一部分:代码 //前端 <head> <meta http-equiv="Content-Type" content= ...
- 【web开发学习笔记】Structs2 Result学习笔记(二)动态结果集
Result学习笔记(二) - 动态结果集 动态结果 一定不要忘了为动态结果的保存值设置set get方法 第一部分:代码 //前端 <% String context = reques ...
- Java Web开发及应用软件方向的学习计划
从接触计算机以来,一直抱有很浓厚的兴趣.我并不擅长与人交际,与机器对话可能更有性格方面的优势.虽然我很想做出一些改变,但总得需要时间和历练,暂时也只能这样了~ 一直很向往代码的神秘,在梦之站待过两年时 ...
- 想做web开发 就学JavaScript
有一天我被问到,为了快速地在 web 开发工作上增加优势,应该学习什么语言.我的思绪回到了大学,那时候我用 Pascal.Fortran.C和汇编语言,不过那个时候有不同的目标. 鉴于当前的状况和趋势 ...
- HTML5移动Web开发实战 PDF扫描版
<HTML5移动Web开发实战>提供了应对这一挑战的解决方案.通过阅读本书,你将了解如何有效地利用最新的HTML5的那些针对移动网站的功能,横跨多个移动平台.全书共分10章,从移动Web. ...
- 【前端】移动端Web开发学习笔记【2】 & flex布局
上一篇:移动端Web开发学习笔记[1] meta标签 width设置的是layout viewport 的宽度 initial-scale=1.0 自带 width=device-width 最佳实践 ...
- 【前端】移动端Web开发学习笔记【1】
下一篇:移动端Web开发学习笔记[2] Part 1: 两篇重要的博客 有两篇翻译过来的博客值得一看: 两个viewport的故事(第一部分) 两个viewport的故事(第二部分) 这两篇博客探讨了 ...
- 《应用Yii1.1和PHP5进行敏捷Web开发》学习笔记(转)
学习地址为: http://www.yiibook.com/book/agile_web_application_development_with_yii1.1_and_php5 1.建立应用程序 ...
- ASP.NET Core Web开发学习笔记-1介绍篇
ASP.NET Core Web开发学习笔记-1介绍篇 给大家说声报歉,从2012年个人情感破裂的那一天,本人的51CTO,CnBlogs,Csdn,QQ,Weboo就再也没有更新过.踏实的生活(曾辞 ...
随机推荐
- Geodetic集合 c++
感谢某位不知名dalao的博客,我才知道怎么解题.... 最开始连题意都读错了....这个故事告诉我们要好好读题 描述 Description 图G是一个无向连通图,没有自环,并且两点之间至多只有一条 ...
- 福州三中集训day3
Day3数据结构,强无敌. 基本讲的是栈,队列,链表,都是些还会的操作,然后接着讲的就比较心凉凉了,先讲了堆,然后是hsah 栈,队列,链表问题都不大,笔记记得都还好,堆就凉凉了. 不会不会不会,没学 ...
- 3、Django实战第3天:数据建模
users modesl.py设计 UserProfile 用户信息 EmailVerifyRecord 验证码 Banner 轮播图 之前我们生成了Django默认的数据表,里面有张表示auth-u ...
- RID枚举工具RidEnum
RID枚举工具RidEnum RID(Relative ID)是域RID主机为域内用户.组或者计算机对象分配的标识.RID和域的SID就构成该对象的SID.RidEnum是一个RID循环攻击工具. ...
- URAL 1682 Crazy Professor (并查集)
[题目链接] http://acm.timus.ru/problem.aspx?space=1&num=1682 [题目大意] 给出k,从1开始不断地加一并把这个数写在黑板上,如果写上的数字和 ...
- Swift中混编OC第三方库
现在Swift的第三方库还比较少,有时候需要使用OC的第三方库,其实也是很容易的. 我们使用如下步骤: 1.新建的Swift项目,第一次创建OC文件时会询问是否生成 桥接头,选择是的话会生成一个桥 ...
- mysql replication 复制的一些问题
1 过大的复制延迟 mysql 的复制延迟是一个常见问题,现在已经有一些解决方案,如淘宝开发的一些工具 2 没有磁盘空间 复制导致磁盘空间塞满,二进制日志.中继日志或临时文件把磁盘塞满,slave ...
- centos系统的时间时区和MySQL的时间时区问题
原文:http://1567045.blog.51cto.com/1557045/1074971 centos系统的时间时区和MySQL的时间时区问题 年轻人做事要细心,特别我们这些搞IT的千万不莽 ...
- 基本的Bootstrap模板
<!DOCTYPE html> <html> <html lang="zh-cn"> <meta charset="UTF-8& ...
- 电脑(台式机||笔记本)开机password忘记通用解决方法
方法:直接制作一个老毛桃装机版u盘启动盘 网址:老毛桃官网 步骤:依照网址的解说,将制作好的U盘插入到电脑的usb插口.执行Windows 登入password破解菜单,搜索password所在的盘符 ...