struts2 access session Id

View: New views
5 Messages — Rating Filter:   Alert me  

struts2 access session Id

by Jakub Milkiewicz :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi
I have a problem with Struts 2.
I am looking for a way to access httpsession id?

I have tried using ActionContext.getContext().getSession().get("id") but it
returns null. i 've read there is a possibility to use Servlet Config
Interceptor<http://www.opensymphony.com/webwork/wikidocs/Servlet%20Config%20Interceptor.html>
but i would not like to do it.

Any help

milo

Re: struts2 access session Id

by Laurie Harper :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Jakub Milkiewicz wrote:
> Hi
> I have a problem with Struts 2.
> I am looking for a way to access httpsession id?
>
> I have tried using ActionContext.getContext().getSession().get("id") but it
> returns null. i 've read there is a possibility to use Servlet Config
> Interceptor<http://www.opensymphony.com/webwork/wikidocs/Servlet%20Config%20Interceptor.html>
> but i would not like to do it.

ActionContext.getSession() gives you access to the session scope
attributes, not the session itself. To get to the actual session object,
obtain the HttpServletRequest object [1] and get the session from there:

     HttpServletRequest request = ...; // use ActionContext or
ServletRequuestAware

     HttpSession session = request.getSession();
     String sessionId = session.getId();

L.

[1]
http://struts.apache.org/2.0.11.1/docs/how-can-we-access-the-httpservletrequest.html


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@...
For additional commands, e-mail: user-help@...


Re: struts2 access session Id

by Jakub Milkiewicz :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I had the same idea when i mentioned Servlet Config Interceptor below but I
just thought there is an easier way.
Anyway thanks for reply and it looks like i need to do just like that.



2008/5/13 Laurie Harper <laurie@...>:

> Jakub Milkiewicz wrote:
>
> > Hi
> > I have a problem with Struts 2.
> > I am looking for a way to access httpsession id?
> >
> > I have tried using ActionContext.getContext().getSession().get("id") but
> > it
> > returns null. i 've read there is a possibility to use Servlet Config
> > Interceptor<
> > http://www.opensymphony.com/webwork/wikidocs/Servlet%20Config%20Interceptor.html
> > >
> > but i would not like to do it.
> >
>
> ActionContext.getSession() gives you access to the session scope
> attributes, not the session itself. To get to the actual session object,
> obtain the HttpServletRequest object [1] and get the session from there:
>
>    HttpServletRequest request = ...; // use ActionContext or
> ServletRequuestAware
>
>    HttpSession session = request.getSession();
>    String sessionId = session.getId();
>
> L.
>
> [1]
> http://struts.apache.org/2.0.11.1/docs/how-can-we-access-the-httpservletrequest.html
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@...
> For additional commands, e-mail: user-help@...
>
>

Re: struts2 access session Id

by krishna chary :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

use this code you will get session id
code is....

ServletActionContext.*getRequest*().getSession().getId();

Re: struts2 access session Id

by Jakub Milkiewicz :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I've found the same code on Struts2 web page.
Thanks anyway


2008/5/14 krishna chary <krishnachary.udaram@...>:

> use this code you will get session id
> code is....
>
> ServletActionContext.*getRequest*().getSession().getId();
>