在struts 2中
<s:property value="#pageTitle" />
(相当于...)
JSTL: ${pageTitle}
我使用的是更紧凑的 JSTL 版本。
我们可以对应用程序消息做同样的事情吗?!要从消息资源中获取文本,我们执行以下操作:
<s:text name="label.sample" />
现在,有没有 JSTL 版本而不是 <s:text/>
?
与此同时,我试图找到一种将 textprovider 传递给 jsp 的方法。但是我找不到方法
public class BaseActionSupport extends ActionSupport{
//Same as ActionSupport
private TextProvider Provider; //with setter and getter
public TextProvider getSampleTextProvider() {
TextProviderFactory tpf = new TextProviderFactory();
if (container != null) {
container.inject(tpf);
}
return tpf.createInstance(getClass(), this);
}
}
在jsp中:
${provider.text("label.password")} //Error The function text must be used with a prefix when a default namespace is not specified
这是正确的方法吗?!
PS:在http://notsoyellowstickies.blogspot.com/2011/05/making-struts-2-and-jstl-share-message.html提到我可以以某种方式共享 struts 2 和 jSTL 消息,但我仍然应该使用 <fmt:message key="sample.label"/>
最佳答案
Action 对象被公开,可以使用它的方法:
${action.getText('sample')}
这是 JSTL 方法调用,您需要 JSTL 2.2(例如:tomcat 7)
(您的操作必须扩展 ActionSupport,才能在上面使用)
关于jsp - Struts 2 使用 JSTL 而不是 s 访问消息 :text,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23846919/