Wed, 13 May 2020 21:46:26 +0200
fixes error pages and adds referer link to error page if it comes from the application
--- a/src/main/java/de/uapcore/lightpit/modules/ErrorModule.java Wed May 13 21:10:23 2020 +0200 +++ b/src/main/java/de/uapcore/lightpit/modules/ErrorModule.java Wed May 13 21:46:26 2020 +0200 @@ -32,6 +32,7 @@ import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServletRequest; +import java.util.Optional; /** * Entry point for the application. @@ -49,10 +50,16 @@ public final class ErrorModule extends AbstractLightPITServlet { public static final String REQ_ATTR_ERROR_CODE = "errorCode"; + public static final String REQ_ATTR_RETURN_LINK = "returnLink"; private ResponseType handle(HttpServletRequest req, int sc) { req.setAttribute(REQ_ATTR_ERROR_CODE, sc); + + Optional.ofNullable(req.getHeader("Referer")).ifPresent( + referer -> req.setAttribute(REQ_ATTR_RETURN_LINK, referer) + ); + setStylesheet(req, "error"); setDynamicFragment(req, "error");
--- a/src/main/resources/localization/error.properties Wed May 13 21:10:23 2020 +0200 +++ b/src/main/resources/localization/error.properties Wed May 13 21:46:26 2020 +0200 @@ -33,3 +33,4 @@ errorTimestamp = Timestamp errorExceptionText = Internal Exception +errorReturnLink = Return to
--- a/src/main/resources/localization/error_de.properties Wed May 13 21:10:23 2020 +0200 +++ b/src/main/resources/localization/error_de.properties Wed May 13 21:46:26 2020 +0200 @@ -33,3 +33,4 @@ errorTimestamp = Zeitstempel errorExceptionText = Interne Ausnahme +errorReturnLink = Kehre zurück zu
--- a/src/main/webapp/WEB-INF/dynamic_fragments/error.jsp Wed May 13 21:10:23 2020 +0200 +++ b/src/main/webapp/WEB-INF/dynamic_fragments/error.jsp Wed May 13 21:46:26 2020 +0200 @@ -28,10 +28,10 @@ <%@page import="de.uapcore.lightpit.modules.ErrorModule" %> <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> - -<jsp:useBean id="exception" scope="request" type="java.lang.Throwable"/> +<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> <c:set scope="page" var="errorCode" value="${requestScope[ErrorModule.REQ_ATTR_ERROR_CODE]}"/> +<c:set scope="page" var="returnLink" value="${requestScope[ErrorModule.REQ_ATTR_RETURN_LINK]}"/> <div id="error-page"> <h1><fmt:message key="h1"/></h1> @@ -48,11 +48,18 @@ <th><fmt:message key="errorTimestamp" />:</th> <td><fmt:formatDate type="both" value="<%= new java.util.Date()%>"/></td> </tr> + <%--@elvariable id="exception" type="java.lang.Exception"--%> <c:if test="${not empty exception}"> <tr> <th><fmt:message key="errorExceptionText" />:</th> <td>${exception.class.name} - ${exception.message}</td> </tr> </c:if> + <c:if test="${fn:startsWith(returnLink, baseHref)}"> + <tr> + <th><fmt:message key="errorReturnLink" />:</th> + <td><a href="${returnLink}">${returnLink}</a></td> + </tr> + </c:if> </table> </div>
--- a/src/main/webapp/WEB-INF/jsp/site.jsp Wed May 13 21:10:23 2020 +0200 +++ b/src/main/webapp/WEB-INF/jsp/site.jsp Wed May 13 21:46:26 2020 +0200 @@ -30,6 +30,9 @@ <%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> <%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> +<%-- Make the base href easily available at request scope --%> +<c:set scope="request" var="baseHref" value="${pageContext.request.scheme}://${pageContext.request.serverName}:${pageContext.request.serverPort}${pageContext.request.contextPath}/" /> + <%-- Define an alias for the request path --%> <c:set scope="page" var="requestPath" value="${requestScope[Constants.REQ_ATTR_PATH]}"/> @@ -56,7 +59,7 @@ <!DOCTYPE html> <html> <head> - <base href="${pageContext.request.scheme}://${pageContext.request.serverName}:${pageContext.request.serverPort}${pageContext.request.contextPath}/"> + <base href="${baseHref}"> <title>LightPIT - <fmt:bundle basename="${moduleInfo.bundleBaseName}"> <fmt:message key="${moduleInfo.titleKey}" />