`
zgw06629
  • 浏览: 30021 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

struts2 动态改变Action resultName

阅读更多

两个目标场景 同一业务逻辑 只是展现页面不同(如标清 高清)

目前的线上程序均是只支持场景1:标清

但现要求亦支持高清

于是想能不能在尽量少的改变原代码的情况下 满足这一业务目标

我一开始的思路是:

添加一请求参数 用以标识何种场景 如epgCode

同时添加一拦截器

return invocation.invoke()+"_"+epgCode

且struts配置文件修改为

<result name="toLogin_010101">/jsp/payment/login.jsp</result>
<result name="toLogin_010102">/jsp/payment/login_hd.jsp</result>

但经测试 不起作用

原因为:

struts2 流程图

现征求可行方案 谢谢!

该业务场景适合使用AspectJ吗?

 

经折腾 发现官方有提供方便的解决方案

详见 com.opensymphony.xwork2.ActionInvocation setResultCode api

 

Sets the result code, possibly overriding the one returned by the action.

The "intended" purpose of this method is to allow PreResultListeners to override the result code returned by the Action.

If this method is used before the Action executes, the Action's returned result code will override what was set. However the Action could (if specifically coded to do so) inspect the ActionInvocation to see that someone "upstream" (e.g. an Interceptor) had suggested a value as the result, and it could therefore return the same value itself.

If this method is called between the Action execution and the Result execution, then the value set here will override the result code the action had returned. Creating an Interceptor that implements PreResultListener will give you this oportunity.

If this method is called after the Result has been executed, it will have the effect of raising an exception.


 

qtl { position: absolute; border: 1px solid #cccccc; -moz-border-radius: 5px; opacity: 0.2; line-height: 100%; z-index: 999; direction: ltr; } qtl:hover,qtl.open { opacity: 1; } qtl,qtlbar { height: 22px; } qtlbar { display: block; width: 100%; background-color: #cccccc; cursor: move; } qtlbar img { border: 0; padding: 3px; height: 16px; width: 16px; cursor: pointer; } qtlbar img:hover { background-color: #aaaaff; } qtl>iframe { border: 0; height: 0; width: 0; } qtl.open { height: auto; } qtl.open>iframe { height: 200px; width: 300px; }

  • 大小: 9.1 KB
分享到:
评论

相关推荐

    struts2零配置个人整理文档

    默认所有的结果页面都存储在WEB-INF/content下,你可以通过设置struts.convention.result.path这个属性的值来改变到其他路径。如: Xml代码 &lt;constant name="struts.convention.result.path" value="/WEB-INF/page" ...

    Struts2属性文件详解

    该属性设置Struts 2是否允许在Action名中使用斜线,该属性的默认值是false.如果开发者希望允许在Action名中使用斜线,则可设置该属性为true. struts.tag.altSyntax 该属性指定是否允许在Struts 2标签中使用表达式语法...

    struts2文件上传

    在struts2中实现文件上传。 &lt;struts&gt; &lt;include file="struts-default.xml"&gt; &lt;constant name="struts.i18n.encoding" value="GBK"&gt; &lt;!--设置临时上传目录--&gt; &lt;constant name="struts.multipart.saveDir" value="d:\...

    struts2配置2.5版

    &lt;display-name&gt;Struts 2&lt;/display-name&gt; &lt;welcome-file&gt;index.jsp &lt;!-- 配置核心拦截器 --&gt; &lt;filter-name&gt;struts2&lt;/filter-name&gt; &lt;!-- Filter的实现类 struts2.5 --&gt; org.apache.struts...

    jfreechar 整合struts2.1.8版本生成线图,饼图,柱形图

    name : result名称 和Action中返回的值相同 type : result类型 不写则选用superpackage的type struts-default.xml中的默认为dispatcher --&gt; &lt;result name="success" type="dispatcher"&gt;/talk.jsp&lt;/...

    Struts2\constant应用

    该属性设置Struts 2是否允许在Action名中使用斜线,该属性的默认值是false。如果开发者希望允许在Action名中使用斜线,则可设置该属性为true。 struts.tag.altSyntax 该属性指定是否允许在Struts 2标签中使用...

    详解struts2的token机制和cookie来防止表单重复提交

    详解struts2的token机制和cookie来防止表单重复提交 ... 当时就想到了用struts2提供的token机制 struts2的token机制防止表单重复... &lt;action name=token class=com.xiaoluo.struts2.TokenAction&gt; &lt;result name=succ

    上传文件,有进度条

    -- 改变struts2默认为2M的上传文件大小限制 --&gt; &lt;constant name="struts.multipart.maxSize" value="1024000000" /&gt; &lt;constant name="struts.multipart.saveDir" value="/temp" /&gt; &lt;package name="struts2" ...

    Struts2的struts.xml配置详细介绍

    配置常量,可以改变Struts 2框架的一些行为 name属性表示常量名称,value属性表示常量值 package元素: 包的作用:简化维护工作,提高重用性 包可以“继承”已定义的包,并可以添加自己包的配置 name属性为必须去且...

    Struts in Action中文版

    2.6.2. Struts的强项........................................................................................................58 Struts in Action 中文版 Lastest Revised:10/14/2005 10:27:00 AM ...

    struts in Action

    2. 深入STRUTS 架构..................................................................................37 2.1. 随便谈谈.......................................................................................

    基于EXT SSI的简单树实现

    &lt;filter-name&gt;struts2&lt;/filter-name&gt; &lt;filter-class&gt;org.apache.struts2.dispatcher.FilterDispatcher &lt;description&gt;struts2初始配置文件 &lt;param-name&gt;config&lt;/param-name&gt; &lt;param-value&gt;conf/...

    spring3.2+strut2+hibernate4

    -- 更改struts2请求Action的后缀名,默认为action。若想去掉后缀,设为","即可 --&gt; &lt;constant name="struts.action.extension" value=","/&gt; &lt;!-- 当配置文件修改后,系统自动加载该文件。开发阶段建议打开此功能...

    jsp探针 ver0.1

    Class.forName("org.apache.struts.action.ActionServlet"); supportStruts = true; } catch (ClassNotFoundException ex) { } try { Class.forName("javax.naming.Name"); supportJNDI = true; } catch ...

Global site tag (gtag.js) - Google Analytics