0

I have a JEE application that uses JQuery / DataTabes, etc

I have an Authenticate routine that checks if the signed on user has permission to run the program. This works up to the point where it should forward to my 'Unauthorized' page. Instead it just returns to the calling jsp as if the user passed authorization.

Here is my jsp code:

  <script type="text/javascript">

        $.ajax({
            url: "${pageContext.request.contextPath}/Authenticate",
            type: "get",
            async: "false",
            cache: "false"


        });
     </script>

and here is my servlet code:

        if (rsAuth.getInt(1) == 0) {
            String unauthorizedPage = "/NotAuthorized.html";
            RequestDispatcher dispatcher = request.getServletContext().getRequestDispatcher(unauthorizedPage);
            dispatcher.forward(request, response);


        } 

The html file is in the root directory of the appplication (along with the index) I am running on Tomcat 8.

 <?xml version="1.0" encoding="UTF-8"?>
 <Context path="/MemberTXN"/>

I tried without the "/" in front of the error file but got a runtime exception : IllegalArgumentException: PathNotAuthorized.html does not start with a "/" character.

Ainsworth
  • 69
  • 3
  • 8
  • Does your `rsAuth.getInt(1)` gives you correct result? I mean is the `if` working like it should? – hiren Mar 22 '18 at 06:29
  • Thank you, hiren for your interest. Yes. I get 0 (which is what i expect with my current test data) – Ainsworth Mar 22 '18 at 12:53
  • Also, if I step through the code, the 'dispatcher.forward(request, response) statement executes and does not throw an exception. However, index.jsp continues to build and the 'NotAuthorized' page is not displayed. – Ainsworth Mar 22 '18 at 13:37
  • Make sure that the `NotAuthorized.html` is directly inside `WebContent` folder of your project. – hiren Mar 23 '18 at 03:55

0 Answers0