title: How to redirect unauthorized user to certain JSP page? (using declarative role based authorization)
body: <p>[working with JEE, MVC-JSP + Servlets, TomEE server, MySQL]</p>
  
  <p>I am using declarative form based authentication, role based authorization. So, basically my <code>web.xml</code> has following content:</p>
  
  <pre><code>&lt;security-constraint&gt;
      &lt;web-resource-collection&gt;
          &lt;web-resource-name&gt;secured&lt;/web-resource-name&gt;
          &lt;url-pattern&gt;/somePage.jsp&lt;/url-pattern&gt;
      &lt;/web-resource-collection&gt;
      &lt;auth-constraint&gt;
          &lt;role-name&gt;ADMINISTRATOR&lt;/role-name&gt;
      &lt;/auth-constraint&gt;
  &lt;/security-constraint&gt;
  
  &lt;security-role&gt;
      &lt;role-name&gt;ADMINISTRATOR&lt;/role-name&gt;
  &lt;/security-role&gt;
  &lt;security-role&gt;
      &lt;role-name&gt;USER&lt;/role-name&gt;
  &lt;/security-role&gt;
  
  &lt;login-config&gt;
      &lt;auth-method&gt;FORM&lt;/auth-method&gt;
      &lt;form-login-config&gt;
          &lt;form-login-page&gt;/login.jsp&lt;/form-login-page&gt;
          &lt;form-error-page&gt;/error.jsp&lt;/form-error-page&gt;
      &lt;/form-login-config&gt;
  &lt;/login-config&gt;
  </code></pre>
  
  <p>User with <code>ADMINISTRATOR</code> role is allowed to access <code>somePage.jsp</code>. And when user with <code>USER</code> role tries to access <code>somePage.jsp</code>, (normally) access is denied with page <code>HTTP Status 403 - Access to the requested resource has been denied</code> returned in browser.</p>
  
  <p>I would like when unauthorized user tries to access <code>somePage.jsp</code> to redirect to some another jsp page that will contain appropriate message. How can this be done? Or, what is the practice of handling unauthorized user access atempts?</p>