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学习笔记(一)简介的更多相关文章

  1. 【web开发学习笔记】Structs2 Result学习笔记(三)带參数的结果集

    Result学习笔记(三)带參数的结果集 第一部分:代码 //前端 <head> <meta http-equiv="Content-Type" content= ...

  2. 【web开发学习笔记】Structs2 Result学习笔记(二)动态结果集

    Result学习笔记(二) - 动态结果集     动态结果 一定不要忘了为动态结果的保存值设置set get方法 第一部分:代码 //前端 <% String context = reques ...

  3. Java Web开发及应用软件方向的学习计划

    从接触计算机以来,一直抱有很浓厚的兴趣.我并不擅长与人交际,与机器对话可能更有性格方面的优势.虽然我很想做出一些改变,但总得需要时间和历练,暂时也只能这样了~ 一直很向往代码的神秘,在梦之站待过两年时 ...

  4. 想做web开发 就学JavaScript

    有一天我被问到,为了快速地在 web 开发工作上增加优势,应该学习什么语言.我的思绪回到了大学,那时候我用 Pascal.Fortran.C和汇编语言,不过那个时候有不同的目标. 鉴于当前的状况和趋势 ...

  5. HTML5移动Web开发实战 PDF扫描版​

    <HTML5移动Web开发实战>提供了应对这一挑战的解决方案.通过阅读本书,你将了解如何有效地利用最新的HTML5的那些针对移动网站的功能,横跨多个移动平台.全书共分10章,从移动Web. ...

  6. 【前端】移动端Web开发学习笔记【2】 & flex布局

    上一篇:移动端Web开发学习笔记[1] meta标签 width设置的是layout viewport 的宽度 initial-scale=1.0 自带 width=device-width 最佳实践 ...

  7. 【前端】移动端Web开发学习笔记【1】

    下一篇:移动端Web开发学习笔记[2] Part 1: 两篇重要的博客 有两篇翻译过来的博客值得一看: 两个viewport的故事(第一部分) 两个viewport的故事(第二部分) 这两篇博客探讨了 ...

  8. 《应用Yii1.1和PHP5进行敏捷Web开发》学习笔记(转)

    学习地址为: http://www.yiibook.com/book/agile_web_application_development_with_yii1.1_and_php5   1.建立应用程序 ...

  9. ASP.NET Core Web开发学习笔记-1介绍篇

    ASP.NET Core Web开发学习笔记-1介绍篇 给大家说声报歉,从2012年个人情感破裂的那一天,本人的51CTO,CnBlogs,Csdn,QQ,Weboo就再也没有更新过.踏实的生活(曾辞 ...

随机推荐

  1. UVA 10340 All in All(字符串,朴素匹配)

    #include <stdio.h> #include <algorithm> #include <cstring> using namespace std; ], ...

  2. HDU3414 Tour Route(竞赛图寻找哈密顿回路)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=3414 本文链接:http://www.cnblogs.com/Ash-ly/p/5459540.html ...

  3. hdu6058

    hdu6058 题意 定义 \(f(l, r, k)\) 函数为区间 \([l, r]\) 第 \(k\) 大的数,如果 \(r - l + 1 < k\),\(f = 0\) .求 \(\su ...

  4. Java中应用多线程的场景?

    最典型的应用比如tomcat,tomcat内部采用的就是多线程,上百个客户端访问同一个web应用,tomcat接入后都是把后续的处理扔给一个新的线程来处理,这个新的线程最后调用到我们的servlet程 ...

  5. English distilled

    [ Any question about the job]关于辞职原因 1. What are the main objectives and responsibilities of the posi ...

  6. 【kmp算法】hdu4763 Theme Section

    kmp中next数组的含义是:next[i]表示对于s[0]~s[i-1]这个前缀而言,最大相等的前后缀的长度是多少.规定next[0]=-1. 迭代for(int i=next[i];i!=-1;i ...

  7. 【二分答案】【中位数】codeforces 394 bun

    bunDescription因为体育老师很喜欢等差数列,所以他要求学生们站队必须按身高站成等差数列.但是有些班级的学生无论如何也无法排成等差数列,于是体育老师从食堂买来了两种神奇的面包.吃一个第一种面 ...

  8. 两道Java面试题!

    body { font-family: 微软雅黑; font-size: 14px; line-height: 2; } html, body { color: inherit; background ...

  9. C# 使用 System.Web.Script.Serialization 解析 JSON

    JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式.易于人阅读和编写.同时也易于机器解析和生成.它基于JavaScript Programming Langu ...

  10. Sublime Text:格式化插件HTML-CSS-JS Prettify

    Sublime Text:插件HTML-CSS-JS Prettify可以格式化HMTL/CSS/JS 1.安装Node.js 2.Sublime中ctrl+shift+p,输入ip: 3.点击Ins ...