I'm new to JSP, I m trying to pass javascript value to jsp method.
In the below loop I m fetching list from java class and looping through with the selected value from dropdown in jsp i.e. yearVal and which value is equal assigning to a java variable. Inside the for loop, its showing the correct value for the String variable but outside the for 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.
<% String valYear=""; %>
<%for(int k=0;k<lists.getYearList().size();k++){%>
    if(yearVal==<%= lists.getYearList().get(k)%>){
        <%valYear = lists.getYearList().get(k);%>
        alert('inside scriptlet:::'+<%=valYear%>); 
    }
<%}%>
    alert('outside scriptlet year val:::'+<%=valYear%>);
In java the arraylist is as below:
public List<String> yearList = new ArrayList<String>();
    public List<String> 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<String> yearList) {
        this.yearList = yearList;
    }
The last value 2018 is assigned to java variable in jsp instead of assigning the variable whicvh is equal in if loop.
Im trying like below:
For ex:
if(month != '11'){
        alert('if::'+month);
        <%abc = true;%>
    }else{
        alert('else::'+month);
        <%abc = false;%>    
    }
Though it is going inside if condition, its not setting abc to true, its setting abc to false.
 
     
     
     
    