The OP has abstracted away most of the details, he is working with Map<String, Object>! The session is not generally struts2s responsibility it, generally it is maintained by the web container. Tomcat/Glassfish, etc. And generally you would consider it in such an environment to always exist. What kind of container are you deploying your application in? I recall there being an interceptor that will attempt to create a session for light weight containers, however if struts needs to create such a session object it is doubtful that the container will be able to use it in a meaningful way.
On Thu, Feb 6, 2014 at 9:58 AM, Maurizio Cucchiara <mcucchi...@apache.org>wrote: > Hi Greg, > I seem to recall that this is not the best way to handle the session and > generally speaking, it always better to abstract as much as possible http's > details > > I could be wrong, but It would be better if your action implements a > specific interface (SessionAware or HttpSessionAware) > > Twitter :http://www.twitter.com/m_cucchiara > G+ :https://plus.google.com/107903711540963855921 > Linkedin :http://www.linkedin.com/in/mauriziocucchiara > VisualizeMe: http://vizualize.me/maurizio.cucchiara?r=maurizio.cucchiara > > Maurizio Cucchiara > > > On 6 February 2014 14:14, Greg Lindholm <greg.lindh...@gmail.com> wrote: > > > I have an Interceptor that wants to put something in the session after > the > > action has executed. > > > > But if the session doesn't already exist I get an exception: > > > > java.lang.IllegalStateException: Cannot create a session after the > response > > has been committed > > How can I determine if the session already exists from within an > > Interceptor? > > > > public String doIntercept(ActionInvocation invocation) throws Exception > > { > > String result = invocation.invoke(); > > Map<String, Object> session = > > invocation.getInvocationContext().getSession(); > > session.put(key, value); // throws exception if session doesn't exist > > return result; > > } > > > > Thanks > > Greg > > >