File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes session in struts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "session in struts" Watch "session in struts" New topic

session in struts

sihani rani
Ranch Hand

Joined: Jun 22, 2010
Posts: 32
In struts , session creation code is1)what is the use of session.put("logined","true")?

2)Map sessionlog=ActionContext.getContext.getSession(); is create new session or get already created session (old session)?

please reply me. thanks in advance.
Ankit Garg

Joined: Aug 03, 2008
Posts: 9462

Struts strives for a clean MVC design, so to decouple your action from the servlet environment, struts allows you to access session (and request, context) attributes through a Map. This way you can test your actions more easily and the actions don't have knowledge that its running in a web application. So when you call ActionContext.getContext.getSession(), you get a Map of Session attributes. If there is no existing session, it will be created, otherwise you'll get a Map of existing session attributes. When you call put on the Map object, you are basically adding a session attribute...

SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
David Newton

Joined: Sep 29, 2008
Posts: 12617

Code is cleaner and easier to test if you implement SessionAware, though. It eliminates the need for an ActionContext in the test environment--all you need is a map.
I agree. Here's the link:
subject: session in struts
It's not a secret anymore!