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; }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值