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:
- Give each game a GameID.
- Store all games in a Map, keyed by GameID. E.g. Map.
- The Map is a property on your servlet (or a bean in your spring application context.)
- The URL contains the game ID as a parameter, which you get in your JSP.
- 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.
精彩评论