在支柱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.getText('sample')}
这是JSTL方法调用,您需要JSTL 2.2(例如:tomcat 7)
请参考:http : //mail-archives.apache.org/mod_mbox/struts-user/201405.mbox/%3CCAMopvkNtiTDB0MV97s-tD4JhhZnfJ2bOMcZXu3NJOvyDu9SVaA@mail.gmail.com%3E
(您的操作必须扩展ActionSupport,才能在上面使用)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句