Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There are different ways the actions could communicate with each other as well as they running in different threads and don't share the action context. The most popular way is to pass parameters with the request or in the URL and XWork converter will convert them to the action properties with the help of OGNL. </p> <p>But I think the purpose of the <code>LoginAction</code> is to authenticate the user by their credentials <code>(email, username, password)</code> and save this information in the session map. It is a common resource that could be shared between actions. To get the session map available to the action and other actions they should implement the <code>SessionAware</code>. It will help the Struts to inject the session map to the action property. If you want to use the session in many actions over the application then to not implement this interface in every action you could create a base action.</p> <pre><code>public class BaseAction extends ActionSupport implements SessionAware { private Map&lt;String, Object&gt; session; public setSession(Map&lt;String, Object&gt; session){ this.session = session; } public Map&lt;String, Object&gt; getSession(){ return session; } } </code></pre> <p>then actions will extend the base action to get the session compability.</p> <pre><code>public class LoginAction extends BaseAction { @Override public String execute() throws Exception { User user = getUserService().findBy(username, email, password); getSession().put("user", user); return SUCCESS; } } </code></pre> <p>Now the user in the session and you could get the session from other action or JSP and <code>user</code> object from the <code>session</code> map.</p> <pre><code>public class InboxAction extends BaseAction { @Override public String execute() throws Exception { User user = (User) getSession().get("user"); return SUCCESS; } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload