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]}
You can refer to a static field using the syntax @class@field. The class must be fully qualified.
用appfuse的方法使用常量定义ConstantsTag, constants.tld
然后在使用的时候
<%@ taglib uri="/tags/cons" prefix="cons" %>在header.jsp中
<%-- Put constants into request scope --%>
然后在使用的地方
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/106285/viewspace-1031434/ ,如需转载,请注明出处,否则将追究法律责任。