开发者

What scope am I in when writing code within a Struts2/Apache Tiles .jsp, and how can I access my current Struts2 Action?

开发者 https://www.devze.com 2023-03-05 23:29 出处:网络
So here I am, writing a JSP script which is called by a Apache Tiles which is called by a Struts2 action. Everything works fine, but I\'m just curious about what scopes I have access to.

So here I am, writing a JSP script which is called by a Apache Tiles which is called by a Struts2 action. Everything works fine, but I'm just curious about what scopes I have access to.

  1. I (think I) understand that the following blocks are in 开发者_如何学Pythonthe JSP's scope, in that I have access to the various JSP implicit objects:

    <% stuff in here (and variations of this type of tag) %>
    
    ${ stuff in here }
    
  2. And I know I can access the Struts2 Action with the various Struts2 Tags, but I only have "bean access":

    <%@ taglib uri="/struts-tags" prefix="s" %>
    <s:property value="beanAccessorHere"/>
    
  3. And then, I only know one way of accessing the actual Action context (I think), but only in a Struts2 "if" tag:

    <s:if test="%{variableInMyAction == null}">
    </s:if>
    

So, I was wondering if

  1. There was a way to access the Action context like #3, but in a more flexible manner like in #1.
  2. If I can use the %{} syntax like in #3 but in any place other than in a Struts "if" tag.

Thanks for your time!


So I believe I've figured it out.

There was a way to access the Action context like #3, but in a more flexible manner like in #1.

I can use <s:property value="%{now_in_action_context}"/> to access variables in my Action, and, in fact, can use the %{} syntax in many different Struts tags.

If I can use the %{} syntax like in #3 but in any place other than in a Struts "if" tag.

(Answered above)

I can also do things like use <s:set name="myVar" value="%{somethingFromAction()}"/> and then, later on, access myVar like so: <s:property value="#myVar.thing"/> to call myVar.getThing() or even <s:property value="%{#myVar.getThing()}"/>.

0

精彩评论

暂无评论...
验证码 换一张
取 消