Kathleen Angeles wrote:You can use HttpSession attributes. It is persistent between calls.
Nico Martens wrote:
Is that a best practice to use HttpSession.
Nico Martens wrote: Should I initialize my HttpSession in my servlet?
Nico Martens wrote: Does the rest controller knows from which session it is called?
Kathleen Angeles wrote:
Nico Martens wrote:
Is that a best practice to use HttpSession.
The http protocol is stateless.
Rest (when using http under it, and all other types of remote calls for that matter like XML Web Service), do not maintain state unless you make it so. Your way of putting your 'test_object' in the HttpSession indeed makes it stateful.
Your Rest service being stateful is bad in some ways; e.g. in service-oriented architecture, maintainability of code due to clean design, performance, etc. For example, the concerned service is no longer purely independent. But if this is what you want, and what your application calls for (for example, small web applications or modules), you can do so.
Nico Martens wrote: Should I initialize my HttpSession in my servlet?
You can access the HttpSession by adding an HttpSession into your controller method's parameters like below.
Nico Martens wrote: Does the rest controller knows from which session it is called?
Yes, because it is part of the servlet specification. For example, a session id is used (e.g. through cookies, or url parameter), which reminds the server which session it is for.
Mark Spritzler wrote:True REST, has a rule of always stateless. So no HttpSession involved.
Mark
Nico Martens wrote:
Mark Spritzler wrote:True REST, has a rule of always stateless. So no HttpSession involved.
Mark
I hear you but I think you can do the same with REST as you can do with a servlet (that's even the reason why I posted in the servlets section).
So why use a servlet as your controller at all. Why use jsp... REST put you in the possition that you can split your view layer.
It's a different way of development I agree, but it would be much smoother for the end-users wouldn't it??
Regards
Nico Martens wrote:I agree with you for reusability reasons. But take the example of simply getting user bound data through REST.
If you don't get your user bound variables through something like a session created by a controller, then I would think that the only alternative is to use parameters.
Isn't that insecure? It's all still a javascript call so you can change the parameters inside a session...
I would like to use knockout to make a Model View View-Model in the front-end.
It's especially the backend that I'm interested in...
Thanks for the reply,
Regards
Nico