title: Passing variable from action class (Struts 2) to JSP
body: <p>Technology used Struts2 and JSP
  In Jsp I am checking my session value as whether it is set or not.</p>
  <pre><code>&lt;s:if test=&quot;%{#session.sessionKey}&quot;&gt;
  </code></pre>
  <p>Now I have another random variable <code>rndmVar</code> in my Action class(I can not set this variable in session scope.), now my session key will be <code>sessionKey</code> variable appended by <code>rndmVar</code> value, so how will check this  new session key in JSP.</p>
  <p>i want something like</p>
  <pre><code>&lt;s:if test=&quot;%{#session.sessionKey+rndmVar}&quot;&gt;  //session key appended by rndmVar value.
  </code></pre>
  <p>First problem how will pass this variable from action class to JSP, and than how will I check it in JSP.</p>
  <p>i tried something like</p>
  <pre><code>public String rndmVar;
  public String getRndmVar() {
    return rndmVar;
  }
  public void setRndmVar(String rndmVar) {
    this.lang = lang;
  }
  </code></pre>
  <p>than in method of action class(this method of action class will redirect to JSP.), I setted this random variable value.</p>
  <pre><code>setRndmVar(&quot;rndmfdfkad&quot;);
  </code></pre>
  <p>I thought var <code>rndmVar</code> was added in value stack and can be accessed using OGNL. but this didn't work.</p>
  <p>Now I am putting values in session object in action class as.</p>
  <pre><code>String randomVar=&quot;fadfjk&quot;;
  String newSessionKey=&quot;sessionKey&quot;+randomVar;
  session.put(newSessionKey,&quot;value_part&quot;);
  </code></pre>
  <p>Now in Jsp I want to check whether <code>newSessionKey</code> variable is set or not. Now how can I pass dynamically key value to JSP.</p>
  <pre><code>&lt;s:if test=&quot;#session['sessionKey' + rndmVar] != null&quot;&gt;
  </code></pre>
  <p>above Syntax is not working, in fact it is always giving <code>null</code> and going in else loop.</p>
  <p>In my action class</p>
  <pre><code>session.put(&quot;sessionKey&quot;+rndmVar,&quot;businessList&quot;); //where businessList is ArrayList&lt;BusinessLogicDTO&gt; businessList
  </code></pre>
  <p>I am able to see <code>rndmVar</code> value in scriplet tags in JSP.</p>
  <pre><code>&lt;% System.out.println(&quot; Random var value passed from action class 2 JSP &quot;+request.getParameter(&quot;rndmVar&quot;)); %&gt;
  </code></pre>