java - Session expiring when redirecting to URL -


it seems when attempt call url modelandview(), session ended , when view loaded, new session created without of data hope persist.

     return new modelandview("redirect:http//.....) 

is there better way handle sessions besides @sessionattributes when moving different controllers?

@sessionattributes session objects not meant shared among controllers. here alternatives:

you can store attributes directly httpsession object. can obtain httpsession object adding controller method parameter:

public modelandview mycontrollermethod(..., httpsession session) {   ...   session.setattribute("someattribute", somevalue);   ... } 

you can autowire httpsession object , use in controller methods:

@autowired private httpsession httpsession; 

you can create session scoped bean , inject bean controllers need it:

<bean id="mysessiondatabean" class="com.example.mysessiondatabeanimpl" scope="session">     <aop:scoped-proxy /> </bean> 

and use in controllers (mysessiondatabeanimpl implements sessiondatabean interface in example):

public class mycontroller {     ....     @autowired     sessiondatabean sessiondatabean;      @requestmapping(...)     public modelandview controllermethod(...) {          ...          sessiondatabean.setsomevalue(somevalue);     } } 

Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -