how to handle 500 error

我只是一个虾纸丫 提交于 2019-12-23 03:23:18

问题


I'm trying to show custom error message for 404/403/500 error. I'm able to show 404/403 error but unable to show 500 error. Steps I have followed so far -

Step 1: Created a servlet which will set the status as 500

   public class ErrorServlet extends SlingSafeMethodsServlet {
    @Override
    protected void doGet(final SlingHttpServletRequest request,
            final SlingHttpServletResponse response) throws ServletException,
            IOException {
                try{
                  response.setStatus(500);
          } catch (Exception e) {
            e.printStackTrace();
          }
        }
      }

Step2: Crated Exception.jsp and Throwable.jsp under apps/sling/servlet/errorhandler

Step3: Added below code in both Exception.jsp and Throwable.jsp

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

Now when I hit __http://port:host/path/to/servlet then I get "Internal Server Error" in the browser. It does not send to the expected custom error page which I mentioned. Kindly let me know what I'm missing here.

来源:https://stackoverflow.com/questions/22452304/how-to-handle-500-error

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!