简体   繁体   中英

How to return a session id from a http server

I have come across many examples of implementing a simple http server in Java. This one fits my needs: http://www.rgagnon.com/javadetails/java-have-a-simple-http-server.html

However, I can't find an example of how to generate, return, and maintain a session id from such a simple http server.

Is that even possible? Is there a way to modify the sample code referred above to incorporate this functionality?

Thanks.

HTTP does not have session support on it self once it is a stateless application protocol. So you need implement it by your self.

For example, on servlet containers like Tomcat there is a cookie called JSESSIONID that is generated and stored on the browser. The client sends back the cookie to the server on each request. Once each client has a different cookie the server can identify the client session.

When cookies are not allowed the parameter JSESSIONID is added to the URL for each request. This technique is called URL Rewriting.

There is a question, not specific for Java HTTP servers, that has implementation details for this problem.

HTTP Session Tracking

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM