struts2 动态改变Action resultName JSPStruts
两个目标场景 同一业务逻辑 只是展现页面不同(如标清 高清)
目前的线上程序均是只支持场景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>
但经测试 不起作用
原因为:
现征求可行方案 谢谢!
该业务场景适合使用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; }