`
zds420
  • 浏览: 199284 次
  • 性别: Icon_minigender_1
  • 来自: 合肥
社区版块
存档分类
最新评论

Struts2 Result 实例

 
阅读更多

 

1:Action result type

常用的四种类型

dispatcher,服务器端跳转

redirect,客户端跳转

chain,动作跳转,服务器端形式

redirectAction,动作跳转,客户端形式

 

2:Action result global results

 

struts.xml

 

 

 <package name="web_result" namespace="/web" extends="struts-default">	
<!-- 全局结果集 -->
		<global-results>
			<result name="globals">/result_file/result.jsp</result>
		</global-results>
		<!-- dispathcher 是服务器端跳转 -->
		<action name="web_result" class="com.result.action.ResultActionDemo01" method="add">
			<result name="success" type="dispatcher">/result_file/result1.jsp</result>
		</action> 
		<!--  redirect 是客户端跳转 -->
		<action name="web_forward" class="com.result.action.ResultActionDemo01" method="add">
			<result name="success" type="redirect">/result_file/result2.jsp</result>
		</action> 
		
		<!-- 客户端跳转  Action的跳转,如果有包则是包之间的跳转 -->
		 
		<action name="web_chain_namespace" class="com.result.action.ResultActionDemo01" method="add">
			
			<!--<result name="success" type="chain">web_action/web</result> -->
			<result name="success" type="chain">
				<param name="namespace">/web_action</param>
		   		<param name="actionName">web</param>
			</result>
		</action> 
		<action name="web_redirect_action" class="com.result.action.ResultActionDemo01" method="add">
			<result name="success" type="redirectAction">web_forward</result>
		</action>  
	</package>
	
	 <package name="extends_action" namespace="/web_extends" extends="web_result">
		<action name="web_extends" class="com.result.action.ResultActionDemo01" >
			<result name="success">/result_file/result4.jsp</result>
		</action> 
	</package>
 

 

java文件

 

 

index.jsp

<a href="/web/web_redirect_action.action?type=3">全局结果集</a><br/>

<a href="/web_extends/web_extends.action?type=3">继承全局结果集</a>

 

 

全局结果集扩展:

 

<global-results>
    <result name="error">/Error.jsp</result>
    <result name="invalid.token">/Error.jsp</result>
    <result name="login" type="redirectAction">Logon!input</result>
</global-results>
 

使用另外一个包中的动态结果使用extends,继承动态结果集的包名。

 

3:Action result dynamic results

 

struts.xml

 

 

 <package name="dynamic" namespace="/dynamic" extends="struts-default">
		<action name="dynamic_action" class="com.result.action.ResultActionDemo01" method="modify">
			<result  name="success">${to_path}</result>
			<result  name="back">/result_file/result.jsp?type=${type}</result>
		</action> 
	</package>
 

 

java 文件

 

package com.result.action;

import com.opensymphony.xwork2.ActionSupport;

public class ResultActionDemo01 extends ActionSupport {
	
	private String type;
	
	public String add() {
		System.out.println("============="+this.type);
		
		if("1".equals(type.toString())) {
			return "success";
		}
		else if("2".equals(type.toString())) {
			return "failure";
		}
		else if("3".equals(type.toString())) {
			return "globals";
		}
		else {
			return SUCCESS; 
		}
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}
}
 

 

 

package com.result.action;

import com.opensymphony.xwork2.ActionSupport;

public class ResultActionDemo01 extends ActionSupport {
	
	private String type;
	private String to_path;
	
	public String add() {
		System.out.println("============="+this.type);
		
		if("1".equals(type.toString())) {
			return "success";
		}
		else if("2".equals(type.toString())) {
			return "failure";
		}
		else if("3".equals(type.toString())) {
			return "globals";
		}
		else {
			return SUCCESS; 
		}
	}
	
	
	public String modify() {
		
		if("home".equals(type.toString())) {
			this.to_path="/result_file/home.jsp";
		}
		else if("details".equals(type.toString())) {
			this.to_path="/result_file/details.jsp";
		}
		else if("contents".equals(type.toString())) {
			this.to_path="/result_file/contents.jsp";		
		}
		else if("list".equals(type.toString())) {
			this.to_path="/result_file/list.jsp";
		} 
		
		if("redirectAction".equals(type.toString())) {
			this.type=type;
			return "back";
		}
		
		return "success"; 
	}
	
	
	
	
	
	
	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}


	public String getTo_path() {
		return to_path;
	}


	public void setTo_path(String to_path) {
		this.to_path = to_path;
	} 
}
 

 

 

index.jsp

 

	<a href="/dynamic/dynamic_action.action?type=home">动态结果集</a>
	<a href="/dynamic/dynamic_action.action?type=redirectAction">结果集带参数</a>

<result>${xxxx}</result>
 

 

在action中保存一个属性,存储具体的结果location

4:带结果参数

   <result>/xx/xx.jsp?xx=xxx</result>

forward:在struts2中只有一个请求在服务器端是可以共享的。

redirect:在strts2中只有一种情况的客户端请求传递参数使用<s:property value="#key.value"/>获取传递过来的参数。

 

 

例如:

 

${}表达式,(不是EL)

 

实验实验,分析分析

 

作业1:

提升能力:

先查Struts2 API 文档,在查GOOGLE

 

作业2:

一手鞋:查看OGNL 标签

 

系统分析设计

 

站在项目经理的角度,

考虑第一问题:界面原型,考虑什么样的架构;

第二问题:设计数据库,

第三问题:确定使用什么架构

第四问题:认真考虑使用什么样子的约定(如:配置,规定,命名等等)

分享到:
评论

相关推荐

    struts2入门实例1

    struts2 最新的入门实例 我自己总结的 呵呵,欢迎提出宝贵的意见 1.Struts2_01_login 对应登录。。 login.jsp---------------------------------------html标签的登陆页面 login_struts2.jsp--------------...

    struts2实例 学生信息管理系统

    struts2实现的学生信息管理系统 &lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" ...

    struts2重定向实例源码

    struts result类型中redirect与redirectAction的使用 包括参数传递。

    struts2入门实例2 经典入门必备

    1.Struts2_01_login 对应登录。。 login.jsp---------------------------------------html标签的登陆页面 login_struts2.jsp-------------------------------采用struts标签的登陆页面 login_struts_...

    struts2入门实例4 经典入门必备

    1.Struts2_01_login 对应登录。。 login.jsp---------------------------------------html标签的登陆页面 login_struts2.jsp-------------------------------采用struts标签的登陆页面 login_struts_...

    struts2入门实例3 经典入门必备

    1.Struts2_01_login 对应登录。。 login.jsp---------------------------------------html标签的登陆页面 login_struts2.jsp-------------------------------采用struts标签的登陆页面 login_struts_...

    简单的STRUTS1应用实例

    简单的STRUTS1应用实例简单的STRUTS1应用实例简单的STRUTS1应用实例简单的STRUTS1应用实例

    完整的struts2框架应用实例.docx

    Struts2 框架应用实例详解 Struts2 框架是一种基于 Java 语言的 Web 应用程序框架,它提供了一个灵活的和可扩展的架构,以帮助开发者快速构建基于 Web 的应用程序。下面是 Struts2 框架应用实例的详细介绍: 一、...

    Struts2详解,Struts2与Struts1的区别

    开发一个Struts2简单实例 5. struts.xml文件 三. Struts2深入开发 6. 常用标签配置和使用 7. 常用&lt;result&gt;标签配置和使用 8. 标签 9. Action类的开发 10. 数据类型转换器 11. 实现文件上传 12. ...

    Struts2实战.pdf

    《Struts 2实战》结合实例介绍了Struts 2框架,主要内容包括Action、Result、Interceptor等框架组件,基于注解的配置选项等新特征,Struts 2插件 FreeMarker,如何从Struts 1和WebWork 2迁移到Struts 2,Ajax标签、...

    Struts2入门教程(全新完整版)

    十二、总结 本教程对struts2的基本知识进行了一些说明,关于struts2的更多详细内容应参看struts2的官方文档及提供的app实例。 下面对struts2的基本执行流程作一简要说明,此流程说明可以结合官方提供的struts2结构图...

    struts2流程与流程图

     一旦Action执行完毕,ActionInvocation负责根据struts.xml中的配置找到对应的返回结果result。 Struts 2的核心控制器是FilterDispatcher,有3个重要的方法:destroy()、doFilter()和Init(),可以在Struts 2的下载...

    Struts2属性文件详解

    Struts2属性文件详解 struts.configuration 该属性指定加载Struts 2配置文件的配置文件管理器.该属性的默认值是org.apache.Struts2.config.DefaultConfiguration, 这是Struts 2默认的配置文件管理器.如果需要实现...

    Struts2中Action接收参数的方法

    Struts2 中 Action 接收参数的方法 Struts2 框架中,Action 组件可以通过多种方式接收参数,这些方式包括使用 Action 的属性、使用 DomainModel 和使用 ModelDriven。下面将详细介绍这些方法: 使用 Action 的属性...

    struts2 in action

    《Struts 2实战》结合实例介绍了Struts 2框架,主要内容包括Action、Result、Interceptor等框架组件,基于注解的配置选项等新特征,Struts 2插件 FreeMarker,如何从Struts 1和WebWork 2迁移到Struts 2,Ajax标签、...

    Struts2练习Demo以及随笔

    Struts的开发步骤、OGNL、ValueStack、Action核心、Result基本原理、Struts2核心标记库、Struts2拦截器、自定义拦截器、UI标记、非UI标记、资源文件国际化等等实例全面使用。

    最新Struts2+jq+ajax+json 学会总要4步‵‵超级简单,里面包含实例

    1. 导入struts2 及json包 asm-3.3.jar asm-commons-3.3.jar asm-tree-3.3.jar commons-fileupload-1.2.2.jar commons-io-2.0.1.jar commons-lang3-3.1.jar freemarker-2.3.19.jar javassist-3.11.0.GA.jar ognl-...

    EJB+JBOSS6.0+STRUT2简单登录实例

    DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"&gt; &lt;struts&gt; &lt;!-- 定义包管理配置的action 继承struts-default.xml中...

Global site tag (gtag.js) - Google Analytics