I used java main servlet to create the session variable. But i am unable to access that session variable from java main2 servlet.
Front-end is Angular2 and back-end is java
Angular2 part
getsess(){
console.log("button press")
var url = "http://localhost:8000/demoApp/main";
var header=new Headers();
header.append('Content-Type','application/x-www-form-urlencoded');
let body=new URLSearchParams();
body.append('username',this.pass);
this._http.post(url,body,{headers:header}).subscribe(
res => console.log(res)
);
}
view(){
let body=new URLSearchParams();
body.append('username',this.pass);
this._http.post("http://localhost:8000/demoApp/main2",body).subscribe(
res => console.log(res)
)
}
inval(){
this._http.get("http://localhost:8000/demoApp/main3").subscribe(
res => console.log(res)
)
Java main servlet part
// TODO Auto-generated method stub
String s=request.getParameter("username");
System.out.println(s);
HttpSession hs=request.getSession(true);
hs.setAttribute("s", s);
System.out.println("session created !! "+ hs.getAttribute("s"));
Java main2 servlet part
HttpSession hs=request.getSession();
System.out.println("another page"+hs.getAttribute("s"));
Output