get session into action class in struts 2.x
JSPs contain implicit session object to use in the jsp pages, when an action in invoked in struts we need to get ‘session ‘ into the action class, we can do this by implementing “SessionAware” interface. Eclipse will ask you to implement an unimplemented method click on that meesage and eclipse will create the method for you called “public void setSession(Map<String, Object> arg0){//TODO}”
- declare a private variable as “Map<String, Object> session” in the action class.
- In the setSession method created as mentioned above write “this.session=arg0;” in place of “//TODO”.
Struts will bring in the session into your session object. you can use the session object anywhere in the code.
example code:
public class ExampleClass extends ActionSupport implements SessionAware{
private Map<String, Object> session;
@Override
public void setSession(Map<String, Object> arg0) {
this.session=arg0;
}
Yep.... I couldn't have said it better myself......
Yep.... I couldn't have said it better myself......
Yahoo results... While searching Yahoo I found this page in the results and I didn't think
Nice Focus.... I really like the direction you've decided to take this blog....