Reading OSGI configuration value inside jsp | Community
Skip to main content
May 9, 2024
Solved

Reading OSGI configuration value inside jsp

  • May 9, 2024
  • 2 replies
  • 807 views

Hi all, 

 

I have a legacy component written in jsp. Can i have sample on how to read an OSGI configuration property inside the jsp. I already have the OSGI configuration service , how can i use it within the component.jsp to set some data attribute to a div for the values configured inside osgi config.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Saravanan_Dharmaraj

@trentdeb  JSP in AEM in 2024 ? Surprised to see that.  Please move to sightly ASAP if possible 

 

For JSP 

Please check this SlingScriptHelper defined objects to access the service.

https://sling.apache.org/documentation/bundles/scripting/scripting-jsp.html#defineobjects

https://sling.apache.org/apidocs/sling9/org/apache/sling/api/scripting/SlingScriptHelper.html

<%@include file="/libs/foundation/global.jsp"%> 
<%@taglib prefix="sling" uri="http://sling.apache.org/taglibs/sling/1.0" %>

<sling:defineObjects />

 

 

2 replies

Saravanan_Dharmaraj
Community Advisor
Saravanan_DharmarajCommunity AdvisorAccepted solution
Community Advisor
May 10, 2024

@trentdeb  JSP in AEM in 2024 ? Surprised to see that.  Please move to sightly ASAP if possible 

 

For JSP 

Please check this SlingScriptHelper defined objects to access the service.

https://sling.apache.org/documentation/bundles/scripting/scripting-jsp.html#defineobjects

https://sling.apache.org/apidocs/sling9/org/apache/sling/api/scripting/SlingScriptHelper.html

<%@include file="/libs/foundation/global.jsp"%> 
<%@taglib prefix="sling" uri="http://sling.apache.org/taglibs/sling/1.0" %>

<sling:defineObjects />

 

 

tushaar_srivastava
Level 6
May 10, 2024

Hi @trentdeb 
Good suggestion by @saravanan_dharmaraj , Please put suggestion to leads to move to Sightly.

By the way here is the solution you can try this way:

<%@include file="/libs/foundation/global.jsp"%> <%@page import="org.apache.sling.api.scripting.SlingScriptHelper"%> <%@page import="com.example.aem.config.MyConfigService"%> <% // Get the SlingScriptHelper SlingScriptHelper sling = slingRequest.getSlingScriptHelper(); // Get your OSGi service MyConfigService configService = sling.getService(MyConfigService.class); // Get the configuration value String myValue = configService.getMyValue(); %> <div data-my-value="<%= myValue %>">...</div>

 

Hope this will help!