What should be the approach to implement custom 404 error page in dd4t using spring MVC as the framework where the error page is created in Tridion?

The status code needs to be modified to 404 as well when this page is returned. How exactly should the Page Controller be modified to achieve this?

Also the URL in the browser should not change and should remain as is entered by the user.

1 Answer 1


A way to do this is to extend the AbstractPageController in such a way that when an ItemNotFoundException is thrown, you attempt to load a 404 page:

// MUST BE A Tridion Published Page
String 404Url = "/errors/404.html";
String currentUrl = HttpUtils.getCurrentURL(request);


    super.showPage(model, request, response);

} catch (ItemNotFoundException e) {
    if (request.getDispatcherType() == DispatcherType.ERROR) {
        if (currentUrl.equals(404Url)) {
            LOG.error("404 page '{}' missing. Is it published from Tridion?", currentUrl);
            response.getWriter().write(currentUrl + " missing");
        } else {
            try {
                request.getRequestDispatcher(404Url).forward(request, response);
            } catch (ServletException se) {
                LOG.error("Impossible to get dispatcher for " + 404Url + ". Performing redirect instead", se);
    } else {
        LOG.info("Page with url '{}' could not be found.", url);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.