我的拦截器没有从操作页面到ftl取值 [英] My interceptors are not fetching values from from action page to ftl

查看:65
本文介绍了我的拦截器没有从操作页面到ftl取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Struts2的新手.我找不到为什么我的ftl无法从操作页面获取值的问题.这是我的ftl代码:

I am new to Struts2. I am not able to find the issue that why my ftl couldn't fetch values from action page. This is my ftl code :

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

这是我的struts.xml:

This is my 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>

这是我的动作课:包MyActions;

This is my action class: package MyActions;

import java.util.Random;

import java.util.Random;

import com.opensymphony.xwork2.ActionSupport;

import com.opensymphony.xwork2.ActionSupport;

导入服务.ColorPicker;

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]

推荐答案

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

Stupid mistake. Instead of writing ${FirstAction?if_exists.random} i should have written ${random?if_exists}.

这不是静态类.

这篇关于我的拦截器没有从操作页面到ftl取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆