在不使用scriptlet的情况下引用JSP中的静态字段 [英] Reference static fields in JSP without using scriptlets
本文介绍了在不使用scriptlet的情况下引用JSP中的静态字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:
来自EL的参考界面常量
所以我有一个JSP当前没有scriptlet,即没有出现<%(<%@除外),而是多次出现$ {javaVar},即EL。
So I have a JSP that currently has no scriptlets in it, i.e. there are no occurrences of "<%" (with the exception of "<%@") and instead multiple occurrences of "${javaVar}", which is EL.
我现在需要添加如下内容:
I now need to add something like this:
<security:hasPermissionTo functionKey="<%= FunctionKeyConstants.CREATE %>" ...
但我不想破坏这个JSP的约定。我可以用EL吗?或者其他任何建议?
But I don't want to break the convention of this JSP. Can I do this using EL? Or any other suggestions?
推荐答案
Java Class
Java Class
public class FunctionKeyConstants{
public static final String NAME="Jigar";
public String getNAME(){//NOTE THAT ITS NOT STATIC
return NAME;
}
}
JSP
<jsp:useBean id="cons" class="com.example.FunctionKeyConstants" scope="session"/>
然后
${cons.NAME}
这篇关于在不使用scriptlet的情况下引用JSP中的静态字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文