开发者

How to handle multiple clients in JSP?

开发者 https://www.devze.com 2023-04-13 01:30 出处:网络
I\'m implementing a game in JSP and Servlets. The game should support multiple players. It is obvious that each player ID is generated on the server side. But where do I store it on the client side, s

I'm implementing a game in JSP and Servlets. The game should support multiple players. It is obvious that each player ID is generated on the server side. But where do I store it on the client side, so I can retrieve it later (from within the servlet) when the client calls for the Servlet?开发者_JS百科


Sessions are handled automatically by the servlet framework, and you retrieve the session by calling request.getSession() in a servlet.

The session is available in different ways once you start using a framework once you outgrow servlets (this happens quickly) and is framework-dependent.


Depends on how long you want the client to remember the player ID.

  1. During the session: The session is a good place
  2. During his subsequent visists: A (permanent) cookie is a good place

Session: request.getSession()

Cookie: request.getCookies() and response.addCookie(cookie)


Session ids are usually stored in a cookie.

I'd be amazed if JSP doesn't have a session library that would take care of all that for you.

0

精彩评论

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

关注公众号