views:

90

answers:

2

My idea is that player 1 creates a game (for two players), server returns him a URL, player 1 sends this URL to player 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?

+2  A: 

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.

mdma
Have you got any ideas about websites where I could learn how to write this or could you sketch out some sample code of it? My problem is that I'm a bit lost in this application scope stuff and I don't know how to put it all together :/
Corvus
+2  A: 

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.

BalusC
I've kinda figured this out myself already. Problem is I don't know how to actually write this application scope map thing :/Could you, please, give me some links, where this is explained, or even better some sample code?
Corvus
JSF and Spring have an "Application scoped bean" concept. Give it a `Map` property. In plain JSP/Servlet you just store the `Map` (or a bean containing the `Map`) as servlet context attribute using `ServletContext#setAttribute()` (that's after all also what JSF/Spring/whateverFramework does under the hoods).
BalusC
Ok, I'll try that and I'll be back when I get desperate again. Thank you very much
Corvus
It works, 'Players' share common 'Game'. But I have problems accessing the 'Players' from the 'Game'. I described the problem in my questions. Any ideas how to fix it, please?
Corvus
This is a new question, you should have asked a new question about this and not reuse an old and already answered question.
BalusC
It's actually part of the original question, but I guess you're right... will do ;)
Corvus