开发者

How can I connect two users so they can share common object (game instance) with use of J2EE web technologies (JSP, Spring etc.)?

开发者 https://www.devze.com 2022-12-31 11:24 出处:网络
My idea is that player 1 creates a game (for two players), server returns him a URL, player 1 sends this URL to player开发者_JAVA技巧 2 and the player 2 opens URL and that connects him to the game.

My idea is that player 1 creates a game (for two players), server returns him a URL, player 1 sends this URL to player开发者_JAVA技巧 2 and the player 2 opens URL and that connects him to the game.

What is the best and the easiest way to achieve this using JSP and related technologies?


You'll need to store the information in some Map in the application scope for which you pass the key around as parameter or pathinfo in the request URL. When the request comes in you just check the presence of the parameter or pathinfo and then retrieve the related information from the Map.


Briefly:

  1. Give each game a GameID.
  2. Store all games in a Map, keyed by GameID. E.g. Map.
  3. The Map is a property on your servlet (or a bean in your spring application context.)
  4. The URL contains the game ID as a parameter, which you get in your JSP.
  5. You fetch the Game from your game map using the GameID, e.g. Game game = map.get(gameID)

This is not terribly good design - but it is simple and will get you started.

0

精彩评论

暂无评论...
验证码 换一张
取 消