Struts 2 <s:if> tag How to get action name to be evaluated in jsp

时光毁灭记忆、已成空白 提交于 2019-11-30 18:27:27

问题


Now I can get any desired results if I use the <s:if> tag in Struts2

    <s:if test="status==1">
         //do some stuff
    </s:if>

but I don't know how to get the action currently executed, I am expecting like

    <s:if test="action==addaction">
         //do some stuff
    </s:if>

回答1:


You can get action name from the context

<s:if test="#context['struts.actionMapping'].name=='addaction'">
   do some stuff
</s:if>



回答2:


Since Struts version 2.3.34 and 2.5.13 #context is not available anymore because of security reasons (see WW-4852) As a workaround you can use #request which is documented here

<s:if test="#request['struts.actionMapping'].name=='addaction'">
   do some stuff
</s:if>



回答3:


Try this

<s:if test='%{com.opensymphony.xwork2.ActionContext.name=="YourActionName"}'>
     //do some stuff
</s:if>


来源:https://stackoverflow.com/questions/21197053/struts-2-sif-tag-how-to-get-action-name-to-be-evaluated-in-jsp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!