1

I've registered an error page:

<error-page>
    <error-code>401</error-code>
    <location>/WEB-INF/exceptions/401.jsp</location>
</error-page>

I trigger an error in my Servlet:

response.sendError(401, "message here");

401.jsp:

<%@page contentType="text/html" pageEncoding="UTF-8" isErrorPage="true"%>
<!DOCTYPE html>
<html>
    ...
    <body>
        <h1>Unauthorized (401)</h1>
        <p><%= exception.getMessage() %></p>
    </body>    
</html>

Unfortunately, only the 'generic' 401 page is displalyed.

I've restarted the application and Tomcat, but no change.

What am I missing?

** edit 0 **

I included the JSP file's code.

It appears that the issue is with the <%= exception.getMessage() %> code. If it is removed, the custom page displays as expected. If it is present, the 'generic' message is displayed.

I substituted this JSTL ${pageContext.errorData.throwable.message}. The custom 401 page is displayed, but the message is blank.

craig
  • 25,664
  • 27
  • 119
  • 205
  • Solved: [What is the simplest way to display httpServletResponse.sendError(403, “My Message”) status from JSTL][1] [1]: http://stackoverflow.com/questions/1104452/what-is-the-simplest-way-to-display-httpservletresponse-senderror403-my-messa – craig Feb 20 '12 at 21:29

1 Answers1

0

AFAIK jsp should be in outside WEB-INF folder, otherwise you have to configure your jsp in web.xml with <jsp-file> tag. Try to put 401.jsp in outside WEB-INF.

Ramesh Kotha
  • 8,266
  • 17
  • 66
  • 90
  • Placing JSP in the WEB-INF is a good practice, as it keeps it from unauthorized access. The problem is with the embedded code, not its location. – craig Feb 20 '12 at 16:56