微信小程序获取不到session值是因为两次的sessionid不同

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 有的话需要清除上次的

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值