The WeChat applet cannot get the session value because the sessionid is different twice

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
Use hei to access the 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/uploadPic6content


@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();
    }
    }

Return to applet

After the applet bai received header value added 'Cookie': 'JSESSIONID ='+that.data.sessionin the cookie JSESSIONID assigned to the received 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;
	
}
}

The above method needs to determine whether the session has been obtained locally. If there is, it needs to clear the last one

Guess you like

Origin blog.csdn.net/weixin_40938312/article/details/103717950