Search code examples
javajspresourcebundle

Do JSP support runtime string substitution for resource bundle text?


In the resource bundle properties file I have following text

system.invalidID = This accountID $ is not valid for current session.

I want to replace dynamically $(this will be the actual ID at runtime) from the above resource text in my JSP and java Class.

Can we do this in JSP and java?


Solution

  • You can actually create a simple class with a method something like

    public class ResourceBundleHelper{
    
        public String resolveMessage(String key){
         //code
        }
    
    } 
    

    and then create instance of this class and put it to ServletContext and then from jsp el

    ${resourceBundleHelper.resolveMessage(YOUR_VARIABLE)}