JSP File - Display an AEM page | Community
Skip to main content
New Participant
June 13, 2018
Solved

JSP File - Display an AEM page

  • June 13, 2018
  • 10 replies
  • 7331 views

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

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 demd43642519

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); %>

10 replies

joerghoh
Employee
June 14, 2018

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

New Participant
June 14, 2018

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

joerghoh
Employee
June 13, 2018

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

Jörg

arunpatidar
New Participant
June 13, 2018

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");

    }

}

Thanks

Arun

Arun Patidar
demd43642519AuthorAccepted solution
New Participant
June 13, 2018

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); %>

New Participant
June 13, 2018

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

arunpatidar
New Participant
June 13, 2018

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

Arun Patidar
kautuk_sahni
Employee
June 13, 2018

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

-Kautuk

Kautuk Sahni
New Participant
June 13, 2018

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";

arunpatidar
New Participant
June 13, 2018

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

Arun Patidar