【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就再也没有更新过.踏实的生活(曾辞 ...
随机推荐
- [Python Debug]Kernel Crash While Running Neural Network with Keras|Jupyter Notebook运行Keras服务器宕机原因及解决方法
最近做Machine Learning作业,要在Jupyter Notebook上用Keras搭建Neural Network.结果连最简单的一层神经网络都运行不了,更奇怪的是我先用iris数据集跑了 ...
- Codeforces #445 Div2 D
#445 Div2 D 题意 给出一些字符串,要求构造一个最短的且字典序最小的字符串,使得给出的字符串都为目标字符串的子串,且这些字符串作为子串出现的次数都是最多的,如果不存在目标字符串输出 &quo ...
- Kattis - boxes (dfn序)
Boxes There are N boxes, indexed by a number from 1 to N . Each box may (or not may not) be put into ...
- Linux命令之last
last [-num | -n num] [-f file] [-t YYYYMMDDHHMMSS] [-R] [-adioxFw] [username..] [tty..] last作用是显示近期用 ...
- Html5+CSS
1. 内联样式是为元素添加样式的最简单有效的方式,但是更易于维护的方式是使用层叠样式表CSS(Cascading Style Sheets). <style> 选择器 {属性名称: 属性 ...
- [BZOJ 1305] 跳舞
Link:https://www.lydsy.com/JudgeOnline/problem.php?id=1305 Solution: 发现res是否可行具有单调性,二分答案 容易看出每次check ...
- 【博弈论】bzoj2463 [中山市选2009]谁能赢呢?
∵都是最优操作 ∴n*n=偶数时Bob赢,否则Alice赢 n*n的奇偶性等价于n的奇偶性. #include<cstdio> using namespace std; int n; in ...
- 使用MR求解多个矩阵的乘积之后
首先介绍涉及到的知识点,如下: 1)value的类型是IntArrayWritable,将整型数组值取出的方法有两种. a.其一,就是使用value的toArray()方法,返回值是一个Object ...
- SweetAlert和MBProgressHUD冲突的解决办法
解决方法 : UIView *view = [UIApplication sharedApplication].keyWindow; NSLog(@" -- &g ...
- springmvc-框架学习
https://www.androiddev.net/springmvc-框架学习一-helloworld/