Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

RequestDispatcher.forward not working properly

Avatar

Level 4

I am calling a java class implementing WCMUse in template's(page component's) sightly (.html) where I am checking something and based on that I need to forward to some other cq page. The issue I am facing here is that the content of the current page remains intact and on top of it, the content of the page to which i want to forward to is being rendered. So I see the forward page and below that I see the header footer content etc again of the current page from where I am forwarding. Ideal behaviour that I need here is like only the content of the page where we are forwarding should come and current page's content should not appear. Java code snippet written in

slingRequest.getRequestDispatcher(pathofthepagetoforward).forward(slingRequest, slingResponse);

Please suggest any solution or may be I am doing something wrong here according to AEM.

1 Accepted Solution

Avatar

Correct answer by
Level 4

Thanks for responses. Just posting my solution that worked. Actually it had nothing to do with the RequestDispatcher. The issue was because of misplaced redirection call. after rendering the current page's header section I was redirecting so the other page that was coming in response was also having the header section so that is why I was seeing two head sections and contents from two pages. I moved the redirection call to the beginning i.e. before rendering of anything. That way it worked fine. 

View solution in original post

3 Replies

Avatar

Level 9

Are there any inheritance from parent page? Please check how you defined your page what components are included in the template

Avatar

Correct answer by
Level 4

Thanks for responses. Just posting my solution that worked. Actually it had nothing to do with the RequestDispatcher. The issue was because of misplaced redirection call. after rendering the current page's header section I was redirecting so the other page that was coming in response was also having the header section so that is why I was seeing two head sections and contents from two pages. I moved the redirection call to the beginning i.e. before rendering of anything. That way it worked fine. 

Avatar

Level 2

@__96  - I also need to implement the same use case in my project.So can you please share the solution with the code snippet or any example.It will help me alot.