Expand my Community achievements bar.

SOLVED

Reading OSGI configuration value inside jsp

Avatar

Level 1

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.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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

 

 

View solution in original post

2 Replies

Avatar

Correct answer by
Community Advisor

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

 

 

Avatar

Level 7

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!