如何使用jstl访问java类中描述的常量值

时间:2012-05-17 03:25:07

标签: jsp jstl constants

我希望使用jstl在jsp中显示在单独的java类techcontants.java中声明的java常量。

public class TechConstants {
   public static final String PART = "Part";
   public static final String DESCRIPTION = "Description";
   public static final String VERSION = "Version";
}

在我的view.jsp中,我需要使用ustl

这样的值
<td class="Thd" width="14%">Part</td>

(我试过这样的<c:outvalue="${TechConstants.PART}">

<td class="Thd" width="20%">Description</td>
<td class="Thd" width="10%">Version</td>

我正在使用spring和jstl,

我是否需要在我的modelandview控制器中获取常量值,我必须将其传递给查看?

若是这样请用控制器代码示例描述一下我在控制器中做什么,或者我可以使用jstl直接在jsp中获取常量?

2 个答案:

答案 0 :(得分:1)

您可以使用JSP表达式标记来完成,请尝试使用以下代码。

<%=TechConstants.PART %>

答案 1 :(得分:-2)

您可以访问绑定到表单的对象的属性。

<form:form method="POST" commandName="user">

您可以使用${user.name}

相关问题