简体   繁体   English

填写Struts2时机 <s:property> JSP页面中的标签

[英]Struts2 timing on filling in <s:property> tags in JSP page

I have a simple struts2 web application with one action class and one interceptor. 我有一个简单的struts2 Web应用程序,其中包含一个动作类和一个拦截器。 The action class has a getter method getTitle() which fetches a string from the session. 动作类具有getter方法getTitle() ,该方法从会话中获取字符串。 The interceptor is on the bottom of the default stack so it executes lastly and first after the invocation. 拦截器位于默认堆栈的底部,因此它在调用之后最后一次执行。 It is built in such a way that it can modify the title that is in the session BEFORE action invocation and AFTER invocation. 它的构建方式使其可以在操作调用之前和之后调用之后修改会话中的标题。 The resulting JSP page then shows this title. 然后,出现的JSP页面将显示此标题。

I thought the following logic would apply: 我认为以下逻辑将适用:

  1. interceptor logic before invocation runs 调用运行之前的拦截器逻辑
  2. action class logic runs 动作类逻辑运行
  3. interceptor logic after invocation runs 调用运行后的拦截器逻辑
  4. struts knows the result and gets the .jsp page in the result struts知道结果并在结果中获取.jsp
  5. struts fills in the <:s> tags in .jsp and call getTitle() from the action class. struts填充.jsp中的<:s>标记,并从操作类中调用getTitle()

However this didn't work. 但是,这没有用。 The resulting JSP always showed the title as it was before step 3 was executed. 生成的JSP始终显示标题,与执行步骤3之前的标题相同。 I added some simple logging in my java code and it confirmed my suspicion. 我在Java代码中添加了一些简单的日志记录,这证实了我的怀疑。 This was the order of execution: 这是执行顺序:

  1. log: interceptor logic before invocation runs 日志:调用运行之前的拦截器逻辑
  2. log: action class logic runs 日志:动作类逻辑运行
  3. log: getTitle() method from action class runs 日志:动作类运行中的getTitle()方法
  4. log: interceptor logic after invocation runs 日志:调用运行后的拦截器逻辑

So somehow step 6 became step 3. Why is this and how can I add logic in my interceptor AFTER action invocation to alter the title? 因此,第6步就变成了第3步。为什么要这样做,以及如何在我的拦截器AFTER操作调用中添加逻辑以更改标题?

Nutshell: implement PreResultListener to have stuff happen before rendering, but after invocation. 果壳:实现PreResultListener以使某些事情在渲染之前发生,但在调用之后发生。

http://struts.apache.org/release/2.3.x/docs/writing-interceptors.html http://struts.apache.org/release/2.3.x/docs/writing-interceptors.html

I don't know what title is, but I'm having a hard time understanding why anything relating to something like a page title, or a book title from a domain object, or much else would need to: 我不知道title是什么,但是我很难理解为什么与页面标题或域对象中的书名或其他内容相关的任何东西都需要:

  1. Be retrieved by an action, or 被某个动作取回,或
  2. Be changed by an interceptor 被拦截器改变

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM