How to make a java web application fully stateless [duplicate]

独自空忆成欢 提交于 2019-11-28 10:38:41

问题


This question already has an answer here:

  • How do I make my Web Application stateless yet still do something useful? 5 answers

I know that there are many discussions on difference between stateful app and stateless app, and that stateless is what function programming language does, every function call with the same args will return the same value.

Does it mean object-oriented language is not able to make a fully stateless application,since every object will typically have state.

Also, in Java web application, we typically need to trace user state,and which is solved by session. But how to do that in distributed system with in stateless way?

When one system dies, and we need the session can be recognized in some way by another server so that the user state will be transferred. Do we need to put the session in the central database(cache)?But is this way stateless?

What will be some things need to be concerned except session) to before we make a java web application stateless?


回答1:


You don't store any client state information on the server, you pass it around to everywhere that needs it and you pass it back to the client when the server needs something changed. That is what stateless means, no state. The server should not have any clue about what state the client is in until the client tells it what the state is.




回答2:


The most simple way is to store the session information in some key-value store. Have a look here: Tomcat: Store session in database

To go "real" stateless, there must be NO session at all. This means: The user will authenticate with every request, and with every request you've got to check the credentials. (It's pretty similar to a session database)



来源:https://stackoverflow.com/questions/26830248/how-to-make-a-java-web-application-fully-stateless

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!