How to save user session by logging in using Java +Angularjs

Asked

Viewed 775 times

2

I was doing a search of how to save the user’s session after he was logged in to the system, I found several examples with cookies, however I am using java + Angularjs, and in the examples I found he used the jsp’s Post method, where it received 2 parameters the Answer and the request, and through the Answer it added the cookie, how can I save the user’s session?

2 answers

2


Use the ngStorage:

var meuApp = angular.module("meuApp", ["ngStorage"]);

meuApp.controller("LoginController", function($scope, $localStorage) {
    $scope.login = function() {
        $localStorage.usuario = "joao";
    }

    $scope.ola = function() {
        $scope.mensagem = "Olá " + $localStorage.usuario;
    }
});

0

Hello, which mvc framework are you using? If Spring is very simple, see the example:

public String salvarUsuarioNaSessao(@RequestParam Usuario usuario, HttpSession session){
// Seta na session
session.setAttribute("usuario", usuario);

//Recupera da session
Usuario usuarioNaSession = (Usuario) session.getAttribute("usuario");
return null;

}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.