Java logic is depend on Adobe Launch script execution | Community
Skip to main content
Level 7
July 12, 2023
Solved

Java logic is depend on Adobe Launch script execution

  • July 12, 2023
  • 1 reply
  • 606 views

Hello all,

 

In my AEM application, in the page properties, I have added Adobe Launch script. Called this script in the page template level(in head.html section). So, during page load time, Adobe Launch script will execute and does many things. One part is it adds some details to cookies, say "launch_cookie".

My Java logic(which I am calling from few components.) will read the launch_cookie value from cookie and uses the values. Now, during page load time Java logic executes first. Then Adobe launch script is adding the value to cookies. So, during the first page load, my java logic is not getting the proper values from cookie. How can i resolve this issue?

Adobe Launch script should execute first. Then, java logic should execute.

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 Nupur_Jain

Hi 

 

The requirment you want to achieve is not possible because Launch Script is JS which is client side script which means it needs user browser/agent to get executed. Java code where you have written some logic on these cookies is server side script and as you mentioned when page is loaded, server side script is executed first and vice versa is not possible.

 

If you really want to achieve some task which is dependent on these cookies, you must take your logic from java(server side) to JS(client side) keeping following in mind:

  1. There are js libraries that allow to read cookies client side which you can use and apply logic and change view in your component.
  2. If logic requires server side java execution, then consider creating some servlet which you can call from js after page load. Since, cookies will be created till that time, servlet will get these cookies in request object.

Hope it helps!

Thanks,

Nupur

1 reply

Nupur_Jain
Adobe Employee
Nupur_JainAdobe EmployeeAccepted solution
Adobe Employee
July 12, 2023

Hi 

 

The requirment you want to achieve is not possible because Launch Script is JS which is client side script which means it needs user browser/agent to get executed. Java code where you have written some logic on these cookies is server side script and as you mentioned when page is loaded, server side script is executed first and vice versa is not possible.

 

If you really want to achieve some task which is dependent on these cookies, you must take your logic from java(server side) to JS(client side) keeping following in mind:

  1. There are js libraries that allow to read cookies client side which you can use and apply logic and change view in your component.
  2. If logic requires server side java execution, then consider creating some servlet which you can call from js after page load. Since, cookies will be created till that time, servlet will get these cookies in request object.

Hope it helps!

Thanks,

Nupur