每个循环无法比较两个EL值

时间:2019-07-03 13:43:53

标签: jsp el

我正在尝试使用三元运算符动态应用背景色

(如果requestscope中的学生姓名与while循环中获得的学生姓名相同,则希望应用颜色)

尝试如下

 <tr style="background:${requestScope.studentname == '${student.name}' ? 'yellow' : ''}";>

public void doGet(HttpServletRequest request, HttpServletResponse response)
              throws ServletException, IOException {

              // Set response content type
              response.setContentType("text/html");

              Student st1  = new Student();
              Student st2  = new Student();
              st1.setName("Pavan");
              st1.setResult("Pass");

              st2.setName("JAI");
              st2.setResult("PASS");

              LinkedHashSet<Student> stuHashSet = new LinkedHashSet<Student>();
              stuHashSet.add(st1);
              stuHashSet.add(st2);

              request.setAttribute("data", stuHashSet);

              request.setAttribute("studentname", "JAI");

              // Actual logic goes here.
              RequestDispatcher rd=request.getRequestDispatcher("myjsp.jsp");  

              rd.forward(request, response);//method may be include or forward  

           }

 <table style="border-spacing: 0px;border: 1px solid #cccccc;text-align: left;">
                  <tbody style="font-size:12px;">
                     <tr style="background-color:#e1e6ec;font-weight:bold;">
                        <td style="padding:15px 10px;"></td>
                        <td style="padding:15px 10px;">Name</td>
                        <td style="padding:15px 10px;">Result</td>

                     </tr>
                     <c:forEach items="${requestScope.data}" var="student">

                            <tr style="background:${requestScope.studentname == '${student.name}' ? '#f2f2f3' : ''}";>
                              <td style="padding:15px 10px;">
                                 <div style="display:inline-block;width:20px;height:20px;margin-right:10px;"></div>
                              </td>
                              <td style="padding:15px 10px;">${student.name}</td>
                              <td style="padding:15px 10px;">${student.result} </td>

                           </tr>





                     </c:forEach>
                  </tbody>
               </table>

0 个答案:

没有答案