在两个不同的html表中显示来自GAE数据存储区的检索数据

时间:2014-03-24 19:59:29

标签: java html jsp google-app-engine google-cloud-datastore

以下是从数据存储中提取数据并将其显示在单个HTML表中的代码。现在,我想基于 statusdate 变量对数据进行分类,并将它们显示在两个不同的HTML表中。

<h2 align="center">The list of Companies with Details is given below:</h2>
<table>
  <tr>
     <td>Company Name</td>
     <td>CTC</td>
     <td>10th %</td>
     <td>PUC/Diploma</td>
     <td>Engg</td>
     <td> History Bclog</td>
     <td>Current Bclog</td>
     <td>Year gap</td>
     <td>Visiting Date</td>
     <td>Status</td>
  </tr>
    <% 

    SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
    Date date=new Date();




    DatastoreService datastore = DatastoreServiceFactory.getDatastoreService(); 
    Query q=new Query("PlacementDB");
    PreparedQuery pq= datastore.prepare(q);

    for(Entity p1:pq.asIterable()){

      String company_name=p1.getProperty("CompanyName").toString();
      String Hist_bclog=p1.getProperty("HistoryBacklogs").toString();
      String Current_bclog=p1.getProperty("CurrentBacklogs").toString();
      String year_gap=p1.getProperty("YearGap").toString();
      String ctc=p1.getProperty("CTCOffered").toString();
      double tenth=Double.parseDouble(p1.getProperty("10th%").toString());
      double twelth=Double.parseDouble(p1.getProperty("12th%").toString());
      double cgpa1=Double.parseDouble(p1.getProperty("CGPA").toString());
      String dateofvisit =p1.getProperty("DateOfVisit").toString();
      Date dateofvisit1 =formatter.parse(p1.getProperty("DateOfVisit").toString());
      String eligible_branch=p1.getProperty("EligibleBranches").toString();
      int comp_h;
      int comp_c;
      int comp_y;
      String statusdate;

      if(dateofvisit1.after(date)){
          statusdate="upcoming"; // display in table 1
      }
      else{
          statusdate="past";    // display in table 2
      }


      if(Hist_bclog.equals("Yes")){
          comp_h=1;
      }
      else{
          comp_h=0;
      }

      if(Current_bclog.equals("Yes")){
          comp_c=1;
      }
      else{
          comp_c=0;
      }

      if(year_gap.equals("Yes")){
          comp_y=1;
      }
      else{
          comp_y=0;
      }


      if(eligible_branch.contains(branch)){

          if(ten>=tenth && twelve>=twelth && cgpa >=cgpa1){

              if(comp_h==1 && comp_c==1 && comp_y==1){
                   eligibility_flag="ELIGIBLE";
              }
              else if((history_bl <= comp_h) &&  (current_bl <=comp_c) &&   (yeargap <= comp_y)){
                  eligibility_flag="ELIGIBLE";
              }
              else{
                  eligibility_flag="NOT ELIGIBLE";
              }
          }
          else{
              eligibility_flag="NOT ELIGIBLE";
          }

 %>
    <tr>
    <td><%=company_name%></td>
    <td><%=ctc%></td>
    <td><%=tenth%></td>
    <td><%=twelth%></td>
    <td><%=cgpa1%></td>
    <td><%=Hist_bclog%></td>
    <td><%=Current_bclog%></td>
    <td><%=year_gap%></td>
    <td><%=dateofvisit %></td>
    <td><%=eligibility_flag %></td>
    <td><%=status_date %></td>
   </tr>
   <%  
   }
   }
   }
   %>   

 </table>
 </body>
 </html>

1 个答案:

答案 0 :(得分:1)

您可以将每个实体放入两个列表中的一个。

LinkedList<Entity> upcomingStatusEntities = new LinkedList<Entity>();
LinkedList<Entity> pastStatusEntities = new LinkedList<Entity>();

for(Entity p1:pq.asIterable()){
    Date dateofvisit1 =formatter.parse(p1.getProperty("DateOfVisit").toString());
    if (dateofvisit1.after(date)){
        upcomingStatusEntities.add(p1);
    }
    else{
        pastStatusEntities.add(p1);
    }
}

现在,您可以遍历每个列表以创建每个表。您可以复制显示代码的表来执行此操作,但实际上您应该创建一个函数来显示此类表并调用它两次,每个List一次。 This article解释了如何将Java函数放在jsp文件中。