Note that there are some explanatory texts on larger screens.

plurals
  1. POUnable to get java variable value inside javascript to pass to java method in jsp
    primarykey
    data
    text
    <p>I'm new to JSP, I m trying to pass <code>javascript</code> value to <code>jsp</code> method.</p> <p>In the below loop I m fetching list from java class and looping through with the selected value from dropdown in jsp i.e. <code>yearVal</code> and which value is equal assigning to a java variable. Inside the <strong>for</strong> loop, its showing the correct value for the String variable but outside the <strong>for</strong> loop its showing the last value in the list. I need to get correct value so that I can pass that String variable to a method.</p> <pre><code>&lt;% String valYear=""; %&gt; &lt;%for(int k=0;k&lt;lists.getYearList().size();k++){%&gt; if(yearVal==&lt;%= lists.getYearList().get(k)%&gt;){ &lt;%valYear = lists.getYearList().get(k);%&gt; alert('inside scriptlet:::'+&lt;%=valYear%&gt;); } &lt;%}%&gt; alert('outside scriptlet year val:::'+&lt;%=valYear%&gt;); </code></pre> <p>In java the arraylist is as below:</p> <pre><code>public List&lt;String&gt; yearList = new ArrayList&lt;String&gt;(); public List&lt;String&gt; getYearList() { if(yearList.isEmpty()){ yearList.add("2012"); yearList.add("2013"); yearList.add("2014"); yearList.add("2015"); yearList.add("2018"); } return yearList; } public void setYearList(List&lt;String&gt; yearList) { this.yearList = yearList; } </code></pre> <p>The last value 2018 is assigned to java variable in jsp instead of assigning the variable whicvh is equal in if loop.</p> <p>Im trying like below:</p> <p>For ex:</p> <pre><code>if(month != '11'){ alert('if::'+month); &lt;%abc = true;%&gt; }else{ alert('else::'+month); &lt;%abc = false;%&gt; } </code></pre> <p>Though it is going inside if condition, its not setting abc to <code>true</code>, its setting abc to <code>false</code>.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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