我用java的主要servlet来创建会话变量。但我是 无法从java main2 servlet访问该会话变量。HttpSession不工作?
前端是Angular2和后端是用java
Angular2部分
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)
)
爪哇主要的servlet部分
// 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"));
爪哇MAIN2 servlet的部分
HttpSession hs=request.getSession();
System.out.println("another page"+hs.getAttribute("s"));
输出
你怎么在这里做会话管理? –
我感觉jsessionid cookie没有设置。你可以尝试直接从浏览器打到网址吗? – Sanj