Session management in Angular 2 Spring Restful webservice -


i learning angular 2. trying session management in angular 2 , spring mvc. found many articles on angular 1 did not find significant on angular2. tried withcredentials: true, did not work.

       var headers = new headers();        headers.append('content-type', 'application/json');        headers.append( 'accept', 'application/json;charset=utf-8');        let options = new requestoptions({headers: headers, withcredentials:true });        return this.http.get('http://localhost:8080/getallproducts', options).map((res:response) => res.json()).subscribe(); 

in product controller, trying session follows.

public @responsebody list<product> getallproducts(httpservletrequest httprequest) {     system.out.println("inside product controller");     httpsession httpsession = httprequest.getsession(false);     list<product> productlist = collections.emptylist();     if (httpsession == null) {         //todo - redirect login page.     } else {         productlist = new arraylist<>();         product product = new product();         product.setdescription("product1 description");         product.setname("product1 name");         product.setprice(bigdecimal.ten);         product.setsku("product1_sku");         productlist.add(product);     } 

but getting session null. created session in login controller , set attribute in session follows.

@responsebody public string login(@requestbody user user, httpservletrequest request) throws jsonexception {     system.out.println("inside login controller");     if ("abc".equalsignorecase(user.getusername()) && "xyz".equals(user.getpassword())) {         httpsession httpsession = request.getsession(true);         httpsession.setattribute("username", user.getusername());     } 


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -