Struts 2 accessing HttpSession object in Controller


            Actions that want access to the user's HTTP session attributes should implement SessionAware


Code

package com;

import java.util.Map;

import org.apache.struts2.interceptor.SessionAware;
 

import com.opensymphony.xwork2.ActionSupport;
 
public class RegisterController extends ActionSupport implements SessionAware{
	private static final long serialVersionUID = 1L;
 
	private String stuname;
	private String stuage;
	
	Map<String,Object> m;
 
	public String getStuname() {
		return stuname;
	}
	public void setStuname(String stuname) {
		this.stuname = stuname;
	}
 
	public String getStuage() {
		return stuage;
	}
	public void setStuage(String stuage) {
		this.stuage = stuage;
	}
 
    public void setSession(Map<String,Object> m)
    {
    	this.m=m;
    }
 
	public String execute()
	{
		m.put("uname",stuname);
		m.put("uage", stuage);

		return SUCCESS;
	}
 
}

Screenshot

                        

            

Download

        Struts 2 Sessionaware maven zip

        Struts 2 Sessionaware war




Related Post

Comments


©candidjava.com