This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
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


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "session in struts" Watch "session in struts" New topic
Author

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
Sheriff

Joined: Aug 03, 2008
Posts: 9307
    
  17

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
Author
Rancher

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.
 
Consider Paul's rocket mass heater.
 
subject: session in struts