我的拦截器没有将值从操作页面提取到Struts2中的FTL
我找不到为什么我的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>
这是我的操作类:
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]
解决方案
愚蠢的错误。我应该写${random?if_exists}
,而不是写${FirstAction?if_exists.random}
。
这不是静态类。
相关文章