tags:

views:

62

answers:

1

I am working on Java web application where I am populating 2 beans by setting up JDBC with my database. I use JSP to view the pages and I am getting proper results in form of tables. One of my table have data about drivers and passengers. The bean is being populated with the entire data. Now I need to utilize JSTL tags to only view the drivers details. So I wrote the following chunk of codes in JSP. I think I am having some problem with the if tag. When I remove it I get the answer but it includes both drivers and passengers. Any suggestions..

<table  width="100%" cellpadding = "2" cellspacing = "0" border= "0">
<c:forEach items='${detailBean.personBean}' var='person' varStatus='status'>
<c:if test='${person.role=='DRIVER' }'>

<tr><td nowrap width = "10%" align="right"><c:out value="VEHNO: " /> </td> <td nowrap  align="left"> <c:out value='${person.vehNo}'/></td></tr>

<tr><td nowrap width = "10%" align="right"><c:out value="ROLE: " /></td> <td nowrap align="left"> <c:out value='${person.role}'/></td></tr>

<tr><td nowrap width = "10%" align="right"><c:out value="DRVRFLAG: " /></td> <td nowrap align="left"> <c:out value='${person.drvrFlag}'/></td></tr>

</c:if>
</c:forEach>
</table>
+3  A: 

Your use of quotes is invalid. Try to follow the standard convention to always use doublequotes for attribute values and use singlequotes only inside EL expressions. Especially the c:if is wrongly quoted. It should look like this:

<c:if test="${person.role=='DRIVER'}">

However, I wonder that it kind of worked for you because it should have yielded a JSP parser error. That might be server dependent.

BalusC
Thanks a lot BaluC, my problem got solved...Your comments have been very useful for me. Could you forward me any JSTL related website where I could learn more?
mona
You're welcome. I already recommended in one of your previous answers to have a look at the coreservlets.com tutorials: [Beginning and intermediate JSP/Servlet tutorials](http://courses.coreservlets.com/Course-Materials/csajsp2.html) :) The JSTL and EL are covered in the second part: [Advanced JSP/Servlet tutorials](http://courses.coreservlets.com/Course-Materials/msajsp.html). Here's a [direct link to the PDF](http://courses.coreservlets.com/Course-Materials/pdf/ajax/JSTL.pdf). Good luck.
BalusC