Hi,

I think the best solution is to implement SessionAware interface and
setSession() method, then you will either add or remove values from
map. Like below:

public class IndexAction implements Action, SessionAware {

    private Map<String,Object> session;

    public void setSession(Map<String,Object> session) {
        this.session = session;
    }

    public String execute() {
        session.put("key", "Some Value");
        return SUCCESS;
    }

    public String doCheck() {
        return SUCCESS;
    }
}

snippet from struts.xml

    <package name="myPackage" extends="struts-default">

        <action name="index" class="pl.org.lenart.s2demo.IndexAction">
                        <result>/jsp/index.jsp</result>
        </action>

        <action name="check" class="pl.org.lenart.s2demo.IndexAction"
method="doCheck">
                        <result>/jsp/index.jsp</result>
        </action>

    </package>

index.jsp to test session value

<html xmlns="http://www.w3.org/1999/xhtml"; xml:lang="en" lang="en">
<head>
        <title>Index</title>
        <s:head />
</head>
<body>
        <s:property value="#session.key"/>
</body>
</html>
        

Go to http://localhost:8080/<context>/index.action and you will see
the value from session, then go to
http://localhost:8080/<context>/check.action and once again you will
see the same value. Go to some other page in Internet and then come
back to http://localhost:8080/<context>/check.action, once again you
will see the same ;-)

Your action is free from hard coded dependency to ActionContext. I
check this and it's working, I'm using Struts 2.1.3-SNAPSHOT


Regards
--
Lukasz
http://www.lenart.org.pl/

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to