struts.xml如何用变量替换<result>WEB-INF/account/ad_tools.jsp</result>的部分路径

问题描述 投票:0回答:1

现在我有了

<result name="success">WEB-INF/account/ad_tools.jsp</result>

我想用这样的东西替换

WEB-INF/account
,我可以得到
{basePath}

我仍然可以在需要时更改变量
<resutl name="success">{basePath}/account/ad_tools.jsp</result>

。 我应该把变量

basePath
放在哪里以及如何做? 或者如果您有其他方法来处理我的问题?
    

java jsp struts2 actionresult
1个回答
0
投票
basePath

放入值栈。您可以通过多种方式做到这一点。例如


basePath

默认会解析结果属性,因此您可以在结果声明中使用它。

ActionContext.getContext().getValueStack().set("basePath", "/WEB-INF/account");

另一种方法是使用约定插件,您可以在其中定义常量

<result name="success">${basePath}/ad_tools.jsp</result>

并使用注释来覆盖约定配置

<constant name="struts.convention.result.path" value="/WEB-INF/account/"/>

© www.soinside.com 2019 - 2024. All rights reserved.