在 Struts 2 中,我的拦截器没有从操作页面获取值到 FTL

My interceptors are not fetching values from action page to FTL in Struts 2

我找不到我的 FTL 无法从操作页面获取值的问题。

这是我的 FTL 代码:

<html>
<head></head>
<body>
<#assign temp = 12311>
<h4>hello world  : ${FirstAction?if_exists.random} #{temp}</h4>
</body>
</html>

这是我的struts.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
   "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
   "http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
    <constant name="struts.enable.DynamicMethodInvocation"
        value="true" />
    <constant name="struts.devMode" value="true" />
  <package name="default" extends="struts-default">
  
    <action name="getTutorial" class="MyActions.FirstAction" >
      <result name="success">/success.jsp</result>
      <result name="failure">/error.jsp</result>
    </action>
    
    <action name="submit" class="MyActions.FirstAction" method="submit"></action>
    
    <action name="callme" class="MyActions.FirstAction" method="myMethod">
      <result name="success">/FreeMarkerPages/testingAction.jsp</result>
      <result name="failure"  type="freemarker">/FreeMarkerPages/FirstFTL.ftl</result>
    </action>
    
  </package>
</struts>

这是我的动作class:

package MyActions;

import java.util.Random;

import com.opensymphony.xwork2.ActionSupport;

import service.ColorPicker;

    public class FirstAction extends ActionSupport{
        private int random;
        public String execute() {
            return "failure";
        }
        public String myMethod(){
            setRandom(9999);
            System.out.println("My method "+random);    
            return "failure";
        }
        
        public String submit(){
            System.out.println(random);
            return null;
        }
        
        public int getRandom() {
            return random;
        }
        public void setRandom(int random) {
            this.random = random;
        }

这是我的 FTL 错误:

FreeMarker template error (HTML_DEBUG mode; use RETHROW in production!)


The following has evaluated to null or missing:
==> FirstAction?if_exists.random  [in template "FreeMarkerPages/FirstFTL.ftl" at line 5, column 22]

您使用了已弃用的 api。参见 Handling missing values

Note:

These operators exist since FreeMarker 2.3.7 (replacing the default, exists and if_exists built-ins).


如果您想了解 Struts 2 中属性是如何解析的,您可以阅读 答案。

愚蠢的错误。我应该写 ${random?if_exists} 而不是写 ${FirstAction?if_exists.random}

这不是静态的 class。