0

I have an application built using Angular JS.
It has 3 views say (A, B and C).
This is how I have configured the route params.

.config(function ($routeProvider){
$routeProvider
.when('/',{
    controller:'aController',
    templateUrl: 'jsps/a.jsp'
})
.when('/b',{
    controller:'bController',
    templateUrl: 'jsps/b.jsp'
})
.when('/c',{
    controller:'cController',
    templateUrl: 'jsps/c.jsp'
})
.otherwise({redirectTo:'/'});

});

All three views have Login Link. Clicking on LogIn will redirect the user to a different page within my application.

The Login is a form, which calls the LoginServlet and on successful authentication I am redirecting the user to my application.

RequestDispatcher rd = request.getRequestDispatcher("index.jsp");
rd.include(request,response);

I also tried with rd.forward(request, response)

index.jsp is the default page which has ng-view.
So by default always view A is loaded after authentication.

Now my situation is when the user is requesting login from B or C, he has to be redirected to that view after authentication.

I have tried request.getRequestDispatcher("index.jsp#/B");
But this doesn't work.

Any suggestions on how this can be achieved?

nijin
  • 556
  • 2
  • 16

1 Answers1

1

The url fragment #/b is not sent to the server (Refer Get anchor from URI for more details). If you need this information on server, you need to use query parameters. The solution would be (pseudocode)

  • Embed this information as query parameter in the login link Eg: <a href="/login?from=/b"></a>
  • Use hidden input field in the login form to hold the query parameter 'from' <input type="hidden" name="from" value="${param.from}">Hence this will be available in to server when the login form is submitted.
  • After login redirect the user "index.jsp#" + request.getParameter("from")
Community
  • 1
  • 1
Deepak N
  • 2,561
  • 2
  • 30
  • 44