문제

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>
도움이 되었습니까?

해결책

You can get action name from the context

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

다른 팁

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>

Try this

<s:if test='%{com.opensymphony.xwork2.ActionContext.name=="YourActionName"}'>
     //do some stuff
</s:if>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top