Accessing Java Constants from JSTL or OGNL

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/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/106285/viewspace-1031434/

你可能感兴趣的:(Accessing Java Constants from JSTL or OGNL)