Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reference static fields in JSP without using scriptlets [duplicate]

Tags:

java

jsp

el

Possible Duplicate:
Reference interface constant from 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 %>" ... 

But I don't want to break the convention of this JSP. Can I do this using EL? Or any other suggestions?

like image 604
Ed . Avatar asked Aug 22 '26 13:08

Ed .


1 Answers

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"/>

then

${cons.NAME}
like image 91
jmj Avatar answered Aug 24 '26 02:08

jmj



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!