1

Please let me know can we create a property in the class file of javabean as a static or final?

If yes, then is it possible to retrieve the same value from the class and display the value on the screen by using the javabean tag in the jsp file as follows:

  <jsp:setProperty/>
  <jsp:getProperty/>
T J
  • 42,762
  • 13
  • 83
  • 138
user460920
  • 887
  • 5
  • 17
  • 27

1 Answers1

1

Yes. Just provide a getter for it. A setter (as required by <jsp:setProperty>) makes no sense as the variable is apparently supposed to be final.

private static final String SOME_CONSTANT = "peek-a-boo";

public String getSOME_CONSTANT() {
    return SOME_CONSTANT;
}

Other than the old fashioned <jsp:getProperty>, you can also just use EL (note that this still requires the getter).

${bean.SOME_CONSTANT}

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555