0

I have a login page login.jsp. User validation is done at server side. data is sent using the $http post request. My doubt is on successful login i want to redirect the user to home page. How do i do this..? Do i need to use the RequestDispatcher in servlet or $window.location in Java script. How angular will handle this issues. Angular js is used to develop Single Page Applications. Can anyone clearly explain this with an example.

asked Jun 30, 2015 at 3:26
2
  • If it's an SPA [Single page application], You're probably looking for angular routing docs.angularjs.org/api/ngRoute/service/$route. If not, Then any of the two approaches will do Commented Jun 30, 2015 at 3:40
  • I have tried using the $window.location. The problem here is the login page has a url like http://localhost:8080/Angular/login.jsp. 2nd page url needs to be http://localhost:8080/Angular/home.jsp. But when i redirect the url is like 'localhost:8080/Angular/test.jsp#/Home.jsp` Commented Jun 30, 2015 at 3:52

3 Answers 3

1

You can inject $location into your controller that handles the login, and use $location.url('/home') as seen here. It would look something like this:

myApp.controller('LoginController', function($location) {
 // whatever code to process login and store user info
 $location.url('/home');
})

I hope that helps!

Jason Cust
10.9k2 gold badges36 silver badges45 bronze badges
answered Jun 30, 2015 at 4:00
Sign up to request clarification or add additional context in comments.

Comments

0

In your JSP code, on successful login, use the

response.setHeader("Location", site);

Useful resource is http://www.tutorialspoint.com/jsp/jsp_page_redirect.htm

answered Jun 30, 2015 at 3:37

Comments

0

in your angular controller you can use

$location.path( "yourpath" );

and dont forget to add

$scope.apply()

after location path

answered Jun 30, 2015 at 4:09

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.