【问题标题】:How to get the action name in freemarker in Struts2?如何在Struts2的freemarker中获取动作名称?
【发布时间】:2011-10-10 18:11:45
【问题描述】:

例如http://localhost/market/pcsuite/edit.action

能否在 freemarker 文件 edit.flt 中获取动作名称“edit”?

【问题讨论】:

  • 有什么理由使用FreeMarker
  • 这里所有的页面都是用 FreeMarker 写的。使用 Freemarker 不好吗? @lschin
  • 还不错,但不是大多数人喜欢的。见stackoverflow.com/questions/tagged/…

标签: java struts2 freemarker


【解决方案1】:
<@s.property value="com.opensymphony.xwork2.ActionContext.name" />

或者

<@s.set var="actionName" value="com.opensymphony.xwork2.ActionContext.name" />

<#-- Use as -->

<@s.property value="actionName" />

<#-- Or other FreeMarker Tags -->

或者

action class中创建一个getter,例如

public String getActionName() {
    return ActionContext.getContext().getName();
}

<@s.property value="actionName" />

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-12-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-05
    • 2011-03-15
    • 1970-01-01
    • 2012-04-12
    相关资源
    最近更新 更多