https://www.cnblogs.com/raincedar/p/8196502.html
https://blog.csdn.net/huihuikuaipao_/article/details/98472783
https://blog.csdn.net/tanga842428/article/details/78600940
https://www.cnblogs.com/MaMaNongNong/p/9127416.html
用hei访问controller **username/film/uploadPic6**
hei:function(){
var that = this;
//var username = e.currentTarget.dataset.username;
// console.log(username);
wx.request({
url: 'http://127.0.0.1:8080/xcxmvc/username/film/uploadPic6',
data: {
//username: '张育嘉',
password: '123',
//var latitude=app.globalData.latitude;/:this.g
},
method: 'post',
header: {
//'content-type': 'application/json' // 默认值
'Content-Type': 'application/x-www-form-urlencoded'
},
success: function (res) {
console.log(res.data);
that.setData({session:res.data});
},
fail: function (res) {
console.log(".....6666.....");
}
})
},
controller username/film/uploadPic6
的内容
@RequestMapping("/username")//用post方式接受表单信息
public class username {
@RequestMapping("/film/uploadPic6")
@ResponseBody
public Object uploadPic(HttpServletRequest request) throws Exception {
request.getSession().setAttribute("projectid","oo");
System.out.println("上传的图片的newName: "+request.getSession());
return request.getSession().getId();
}
}
返回给小程序
小程序bai接收到值后 在header中添加 'Cookie': 'JSESSIONID ='+that.data.session
在cookie中给JSESSIONID赋值为接收到的sessionid
bai: function () {
var that = this;
console.log(that.data.session);
//var username = e.currentTarget.dataset.username;
// console.log(username);
wx.request({
url: 'http://127.0.0.1:8080/xcxmvc/username/dll',
data: {
//username: '张育嘉',
password: '123',
//var latitude=app.globalData.latitude;/:this.g
session6:that.data.session
},
method: 'post',
header: {
//'content-type': 'application/json' // 默认值
'Content-Type': 'application/x-www-form-urlencoded',
'Cookie': 'JSESSIONID ='+that.data.session
},
success: function (res) {
},
fail: function (res) {
console.log(".....6666.....");
}
})
},
controller /username/dll
@RequestMapping("/username")//用post方式接受表单信息
public class username {
@RequestMapping("/dll")
@ResponseBody
public userbean bean(userbean bean,HttpServletRequest request,HttpServletResponse response){
String id = (String) request.getSession().getAttribute("projectid");
// String session =request.getHeader("Referer");
// Cookie cookie=new Cookie("JSESSIONID", id);
// cookie.setPath("/");
//response.addCookie(cookie);
System.out.print(id+";;;;;;;;;;;"+request.getSession().getId()+session);
return bean;
}
}
上面的方法需要判断本地有没有获取到session 有的话需要清除上次的