简体   繁体   中英

Can't compare two Strings in a JSP file

I have this Jsp file

<SELECT name="brandsFrom" onchange="as()">
    <c:forEach items="${brandsSelectedList}" var="brands">
        <c:if test="${brands.name == nam}">
        <option value="${brands.id}">${brands.id}</option>
        </c:if>
    </c:forEach>
</SELECT>

i have declared nam above this code like

<%!
String nam;
%>
<%
nam=request.getParameter("name"); 
out.println("value in the string ="+nam+"+");
%>

When i use

<c:if test="${brands.name == nam}">

the code doesn't rum whereas when i use something like this

<c:if test="${brands.name == 'Denim'}">

the code runs . Why am i not being able to use nam variable ??

It could be because brands.name is coming from brandsSelectedList which would be being set in your ActionSerlvet overridden method whereas nam is a local variable defined in JSP. Variables defined in jsp might not be accesible in your expression langauge code. I haven't tried but look at the corresponding generarted class file through a decompiler for JSP and see what's going on there

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM