【问题标题】:how to check property value in class that resides in ArrayList from Jsp page using <c:if>如何使用 <c:if> 从 Jsp 页面检查驻留在 ArrayList 中的类中的属性值
【发布时间】:2013-02-12 07:37:37
【问题描述】:

我在 Request scope 中有 Arraylist ,其中包含所有 Students 对象。 我在JSP page 中显示该数据

class Student 
  {

   int sno;
   String name;
   String type; // here type can be either R or D
    .
    .
    .
  }

当我显示Student obj 数据时,我想检查student type if type=D 然后我想添加 &lt;select&gt; 框 这个怎么办???

我正在使用struts 1.3JDBC

我的代码是

 <logic:iterate id="student" name="allstudents" scope="request">

   <bean:write name="student"   property="sno" format="#"/><br>
   <bean:write name="student"   property="name" /><br>
   <bean:write name="student"   property="type" /><br>


   // here i want to display <select> if type =D
    .
    .
    .
 </logic:iterate>

请帮帮我

提前致谢

【问题讨论】:

    标签: jsp struts jstl


    【解决方案1】:

    帮自己一个忙,学习 JSTL。完成后,使用&lt;c:forEach&gt;&lt;c:out&gt;&lt;fmt:formatNumber&gt;&lt;c:if&gt; 标签:

    <c:forEach var="student" items="${allstudents}">
    
        <fmt:formatNumber value="${student.sno}" pattern="#"/>
        <c:out value="${student.name}"/>
        <c:out value="${student.type}"/>
        <c:if test="${student.type == 'D'}>
            ...
        </c:if>
    
    </c:forEach>
    

    【讨论】:

      【解决方案2】:
      i tried like this this is working fine...
      thank you JB Nizet....
      
       <logic:iterate id="student" name="allstudents" scope="request">
      
             <bean:write name="student"   property="sno" format="#"/><br>
             <bean:write name="student"   property="name" /><br>
             <bean:write name="student"   property="type" /><br>
      
      
             <c:if test="${student.type == 'D'}>
             ......
             </c:if>
      
           </logic:iterate>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-07-28
        • 2017-02-25
        • 1970-01-01
        • 2012-02-26
        • 2014-02-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多