我实际上是在使用 GAE 构建聊天室,问题是我将 clientid 和令牌存储在 chatrromservlet 中,并使用数据存储密钥在 sayservlet 中访问它们,但是当我尝试使用密钥从 sayservlet 访问数据存储时,我得到了一个异常找不到带有密钥的实体。
我的聊天室servlet
String clientid = request.getParameter("clientid");
ChannelService channelService = ChannelServiceFactory.getChannelService();
String token = channelService.createChannel(clientid);
channelService.sendMessage(new ChannelMessage(token, "Hello World"));
System.out.println("token is ="+token);
JSONObject job=new JSONObject();
job.put("token",token);
Key userkey=KeyFactory.createKey("users", "user1");
System.out.println("user key in chatroom "+ userkey);
Entity ent=new Entity("user");
ent.setProperty("clientid", clientid);
ent.setProperty("token", token);
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
datastore.put(ent);
System.out.println(ent);
并且说servlet是
String message = request.getParameter("message");
String clientid = request.getParameter("clientid");
System.out.println(message);
Key userkey=KeyFactory.createKey("users", "user1");
Entity entity;
DatastoreService datastore = DatastoreServiceFactory
.getDatastoreService();
entity = datastore.get(userkey);
String token = (String) entity.getProperty("token");
System.out.println("token frm db ="+token);
ChannelService channelService = ChannelServiceFactory.getChannelService();
channelService.sendMessage(new ChannelMessage(token, "Hello World"));
System.out.println("message is ="+message);
System.out.println("cid is ="+clientid);
如果访问时有任何错误,请帮助我。