相当于Struts 1.x的"bean:define"标签? [英] Equivalent to Struts 1.x "bean:define" tag?

查看:93
本文介绍了相当于Struts 1.x的"bean:define"标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将旧的Struts 1.x应用程序转换为Spring MVC,并且在某些JSP页面中,bean:define标记用于从资源束中获取字符串,然后在以后的版本中使用.页面:

I'm working on converting an old Struts 1.x application to Spring MVC and in some of the JSP pages, the bean:define tag is being used to get a string from a resource bundle, and is then used later in the page:

<bean:define id="example_title"><fmt:message bundle="${example_Labels}" key="example_field"/></bean:define>

然后再说:

title="<%=example_title%>"

我不确定等效的JSTL(或者甚至应该是JSTL)标记是什么,以便取消Struts标记,有人可以提出建议吗?我已经尝试过使用JSTL setjsp:useBean,但是要么它们是错误的方法,要么我没有正确实现它们.

I'm not sure what the equivalent JSTL (or if it even should be JSTL) tag should be in order to do away with the Struts tag, can anyone offer a suggestion? I've tried playing with JSTL set, and jsp:useBean, but either they're the wrong way to go or I'm implementing them improperly.

谢谢您的建议!

推荐答案

使用fmt:messagevar属性.

<fmt:message bundle="${example_Labels}" key="example_field" var="example_title" />

这基本上将与键关联的值导出到名为example_title的页面范围变量中.您可以稍后在页面上使用常用的EL方法进行打印:

This basically exports the value associated with the key into a page scoped variable named example_title. You can print it later in the page the usual EL way:

title="${example_title}"

或者如果您仍在JSP-2.0之前的版本中,不支持模板文本中的EL(请考虑升级..),请使用<c:out>进行显示:

Or if you're still on pre-JSP-2.0 where EL in template text isn't supported (consider upgrading..), then use <c:out> to display it:

title="<c:out value="${example_title}" />"

这篇关于相当于Struts 1.x的"bean:define"标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆