Accessing Java Constants from JSTL or OGNL

zenzuguo發表於2010-02-25

Accessing Java Constants from JSTL

Even there could be many variations to the above code, more creative, funnyer or smarter, this is not my recommended solution. Following the Principle No. 6 from our internal guide, the “DRW concept” (don’t reinvent the wheel :) ), the solution is simple: the unstandard tag library from Apache. Here’s how to use it: and later in you code, an expression like: ${users[Constants.NAME]}

and later in you code, an expression like:

${users[Constants.NAME]}

OGNL - Getting Static Fields

Getting Static Fields

You can refer to a static field using the syntax @class@field. The class must be fully qualified.

用appfuse的方法使用常量定義ConstantsTag, constants.tld

然後在使用的時候

在header.jsp中


然後在使用的地方

constantstaglib.zip

[@more@]

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/106285/viewspace-1031434/,如需轉載,請註明出處,否則將追究法律責任。

相關文章