Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

JSP File - Display an AEM page

demd43642519
Level 4
Level 4

Hi community !

I have a JSP file and an AEM page, how do i make that JSP file to display my AEM page?

I can't find anything related to, it's that even possible ?

Edited: I'm also thinking at an internal redirect. This should also work for my purpose.


Thanks

1 Accepted Solution
demd43642519
Correct answer by
Level 4
Level 4

So, I've used this in my 404.jsp and I achieved what i wanted

<%@include file="/libs/foundation/global.jsp"%> 
<%@taglib prefix="sling" uri="http://sling.apache.org/taglibs/sling/1.0" %><%
%><sling:defineObjects /><%
response.setStatus(404);
request.getRequestDispatcher("/content/demo/somepage.html").forward(request,response); %>

View solution in original post

0 Replies
Arun_Patidar
Community Advisor
Community Advisor

Hi,

What are you using for display AEM page JSP or HTL?

JSP - you can try below to include JSP in AEM Page

  1. <%@ include file="resourceName" %> 
  2. <jsp:include page="..." />

HTL - data-sly-include is to use include other html/jsp resources.

Thanks

Arun

demd43642519
Level 4
Level 4

HI !

I have an JSP file and within this JSP file i want to display I page made in AEM which is found under /content/name-of-the-project/page-name

I have no clue how to bind them. I also thought about a redirect but my issue with is with the root path. How do i get the relative path ?

for now i'm using something like this   

     String redirectURL = "http://localhost:4502/content/demo/somepage.html";

but i want something like

     String redirectURL = "/demo/somepage.html";

kautuk_sahni
Community Manager
Community Manager

I did not get your ask clearly. Please help us elaborate this.

-Kautuk

Arun_Patidar
Community Advisor
Community Advisor

Hi

Can you share some example, where is your JSP and where is your AEM page and why can't you use path from root?

or if you setup vanity URL to avoid /content/ is this feasible or not?

Please help us to replicate or implement.

Thanks

Arun

demd43642519
Level 4
Level 4

So

I've overlayed the the script under the libs/sling/servlet/errorhandler/ so i can have my own custom 404 error script. And for that I want to use a page which I made on AEM.

So my JSP script is under /apps/sling/servlet/errorhandler/404.jsp and my page is under /content/demo/404

How can i bind them ?

That's what I'm willing to achieve

demd43642519
Correct answer by
Level 4
Level 4

So, I've used this in my 404.jsp and I achieved what i wanted

<%@include file="/libs/foundation/global.jsp"%> 
<%@taglib prefix="sling" uri="http://sling.apache.org/taglibs/sling/1.0" %><%
%><sling:defineObjects /><%
response.setStatus(404);
request.getRequestDispatcher("/content/demo/somepage.html").forward(request,response); %>

View solution in original post

Arun_Patidar
Community Advisor
Community Advisor

Hi,

You can use HTL also for creating custom error pages functionality

for that you need to create 404.html and ResponseStatus.java inside /apps/sling/servlet/errorhandler

(You may create ResponseStatus.java outside repo and deployed as part of bundle)

Sample codes below :

404.HTML

<sly data-sly-use.responseStatus="apps.sling.servlet.errorhandler.ResponseStatus" />

<sly data-sly-resource="${'/content/AEM63App/en/page-not-found.html'}"></sly>

ResponseStatus.java

package apps.sling.servlet.errorhandler;

import com.adobe.cq.sightly.WCMUsePojo;

public class ResponseStatus extends WCMUsePojo {   

    @Override

    public void activate() throws Exception {

        getResponse().setStatus(404);

        getResponse().setContentType("text/html");

    }

}

Screen Shot 2018-06-13 at 3.59.38 PM.png

Thanks

Arun

Jörg_Hoh
Employee
Employee

And please please, pay attention to the HTTP response statuscode! arunp99088702​'s example demonstrates how to do it right.

Jörg

demd43642519
Level 4
Level 4

That's really helpful, thanks!!

But i can't really make it work with error 500.

I get this:

Error while processing /content/ui-centre/500.html

Status

500

Message

org.apache.sling.api.SlingException: Exception during response processing.

Location/content/ui-centre/500.html
Parent Location/content/demo
Path

/content/ui-centre/500.html

Refererhttp://localhost:4502/content/demo/page.html
ChangeLog

<pre></pre>

Go Back

Modified Resource

Parent of Modified Resource

Jörg_Hoh
Employee
Employee

That's the error as displayed by the Sling Post Servlet. If you want to have proper error handling for them as well, at the moment it's not possible to handle both POST and GET the same way. See [1] for a way howto implement it.

Jörg

[1] [SLING-7552] SlingPostServlet error handling still insufficient - ASF JIRA