Spring Webflow 访问在 JSP 中使用 context.getFlowScope().put(key, O



我是Spring Webflow的新手,这是我的问题:

我在我的操作类中创建了一个流域变量,如下所示:

public void getStatusValue(HttpServletRequest req, RequestContext context) {
    //This 'appStatus' value will return either "yes" or"no"
    String status = req.getSession(true).getAttribute("appStatus");
    if("yes".equalsIgnoreCase(status)){
        context.getFlowScope().put("applicationStarted" , "yes");
    } else {
        context.getFlowScope().put("applicationStarted","no");
    }
}

我使用

<on-entry>
    <evaluate expression = "Action.getStarted(FlowRequestContext)"/>
</on-entry>
getStarted() 方法

将调用 getStatus() 方法。
我能够使用

context.getFlowScope().get("applicationStarted") 

它打印在动作类中

现在,在JSP上,我正在尝试以这种方式检索"applicationStarted"变量的值

<script type=text/javascript">
var status = ${applicationStarted};
alert(status);
if(status == "yes")
//do something
else
//do something

问题是:1.警报根本没有打印并且不知何故,JSP中的if条件无法执行,所以我无法使逻辑正常工作

有人可以指导我吗?

编辑:搜索后,我了解到 JavaScript 无法直接访问 webflow 变量,所以我尝试在 jsp 中使用 <c:set> 标签,并尝试这样设置:

<c:set var="applicationStarted" scope="session" value="     {applicationStarted"}"/>

在 JavaScript 中:

var status = "<c:out value='${applicationStarted}'/>";

我仍然看不到打印的警报,并且逻辑不起作用。我确定我可能在语法上遗漏了一些东西。

任何帮助将不胜感激。

我想出了上述问题的解决方案。对于遇到相同问题的其他人,这是解决方法。

在 JavaScript 上,同时使用只需提供如下所示的会话范围:

var status = "<c:out value='${sessionScope.applicationStarted}'/>";

并且将填充"状态"的值

最新更新