maintain state with spring between requests

巧了我就是萌 提交于 2019-11-30 07:50:27

You can either put the modelMap in the HttpSession, or (preferable for larger applications), use Spring web flow where you can have the so called conversations.

The cleanest way to do this in Spring is with a session-scoped spring bean. Instances of the bean will be private to the session, and will be instantiated and managed by Spring when each session starts. This bean can hold your conversation state.

Under the covers, this mechanism uses standard HttpSession attributes, but it means your code doesn't have to deal with HttpSession directly, so it's cleaner overall.

See the relevant part of the Spring docs (and here) for how to configure and use it.

Karl

thanks a lot for your suggestions, I solved it by tagging the keys for the ModelMap as session-attibutes:

@SessionAttributes( { "question_index", "something" })  
@Controller  
public class MyController{  
...  
}  

Typically (and without Spring), such data would go into the servlet session.

do it yourself.

<form:form action="bla" method="POST"  modelAttribute="data">
    <input type="hidden" name="data" value="${data}"/>
</form:form>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!