자바 페이지 의 프론트 페이지 와 백 엔 드 코드 구현

본 논문 의 사례 는 자바 페이지 에 표 시 된 구체 적 인 코드 를 공유 하여 여러분 께 참고 하 시기 바 랍 니 다.구체 적 인 내용 은 다음 과 같 습 니 다.
먼저 위의 그림 을 보 세 요.대체적으로 그림 과 같 으 면 아 이 디 어 를 제공 합 니 다(ps:SSH 프레임 워 크 를 사 용 했 습 니 다)

프론트 JSP 페이지

<%@ page language="java" contentType="text/html; charset=utf-8"
 pageEncoding="utf-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>  
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
 <title>     </title> 
 <script type="text/javascript"> 

 //1   ,    disable     
 /*
 $(function(){
  var myPageId="#"+$("#hidCurrentPage").val();
  var myPageAId="#"+$("#hidCurrentPage").val()+" a";
  $(myPageAId).addClass('main-bgcolor');
  $(myPageAId).attr('href','javascript:void(0)')
  $(myPageId).addClass('disabled');
  $(myPageId).addClass('disabledControl');

 })
 */
 //
 $(function(){

 })
 //          
 function queryRequirListByPage(i) {
  var pageNo=i;
  var sortValue=$('#hidSortValue').val();
  $.ajax({
   url:'${pageContext.request.contextPath}/bid/reAction_queryRequirListByPage.action',
   type:'POST',
   data:{
    sortValue:sortValue,
    pageNo:pageNo
   },
   success:function(datas){ 
    $('#requireContentDiv').html(datas);          
   },
   error:function(){
    alert("  ");
   },
   });
 }

 //          
 function selectPage(obj){
  var pageNo=obj.options[obj.selectedIndex].value;
  var sortValue=$('#hidSortValue').val();
  $.ajax({
   url:'${pageContext.request.contextPath}/bid/reAction_queryRequirListByPage.action',
   type:'POST',
   data:{
    sortValue:sortValue,
    pageNo:pageNo
   },
   success:function(datas){ 
    $('#requireContentDiv').html(datas);          
   },
   error:function(){
    alert("  ");
   },
   });
  }
 //          
 function selectSort(obj){
  var sortValue = obj.options[obj.selectedIndex].value;
  var pageNo =1;
  $.ajax({
   url:'${pageContext.request.contextPath}/bid/reAction_queryRequirListByPage.action',
   type:'POST',
   data:{sortValue:sortValue,
     pageNo:pageNo
    },
   success:function(datas){ 
    $('#requireContentDiv').html(datas);


   },
   error:function(){
    alert("  ");
   },
   });
  }

  $(document).ready(function(){
   var backSortValue=$('#backSortValue').val();
   console.log("backSortValue"+backSortValue)
   $("#category option").each(function(){
    var thisId='#'+this.id;
    var thisValue=this.value;
    if(backSortValue==thisValue){
     $(thisId).attr('selected','selected');
    }
   });
  })
 </script> 
</head>
<body>

    <!--   -->
    <div class="well">
    <!--   -->
     <div class="box"><h3><span class="glyphicon glyphicon-list" ></span>    </h3></div>
    <!--     --> 
     <div class="box">
      <div class="row">
       <div class="col-xs-12">        
         <span>  : </span>
         <select id="category" name="category" onchange="selectSort(this)">
          <option id="categoryTime" value="publishDatetime">  </option>
          <option id="categoryPrice" value="price">    </option>
          <input id="backSortValue" type="hidden" value="${sortValue}">
         </select>
         <hr class="mrgZero mrgTopSma"/>
       </div>
      </div>
     </div>     
    <!--   -->
      <input type="hidden" name="hidCurrentPage2" id="hidCurrentPage" value="${currentPage}">
      <input type="hidden" id="hidAllPage" value="${allPage}">
      <input type="hidden" id="hidSortValue" value="${sortValue}">
      <s:iterator value="#requiList">

      <div class="data-down-box">
       <div class="row">
        <div class="col-xs-12">
         <h4 class="ellipsis"><a href="${pageContext.request.contextPath}/bid/bidAction_queryById?id=${id}" rel="external nofollow" onclick="reward()">${title}</a></h4>
        </div>                         
       </div>
       <div class="row mrgTopSma">
        <div class="col-xs-12 ">      
         <p class="data-provider padLeftBig sec-color ellipsis">    :<span>${price}</span></p>
         <p class="data-intro padLeftBig ellipsis sec-color">    :<span>${requirementDescription}</span></p>
        </div>    
       </div>
       <hr/>  
      </div>

      </s:iterator>
     <!--    -->
     <div id="rePagerDiv" class="rePagerDiv box">
      <nav>
       <ul class="pager">

        <!--         1,    1      , --> 
        <s:if test="1 == #currentPage">  
        </s:if>
        <s:else>
        <li>  
         <a href="javascript:void(0)" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" aria-label="Previous" onclick="queryRequirListByPage(${currentPage-1})">
         <span aria-hidden="true">&laquo;</span>
         </a>
        </li>  
        </s:else>

       <!--    -->        
       <li><a href="javascript:void(0)" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" onclick="queryRequirListByPage(1)">  </a></li>

       <li>
        <span><span class="main-color">${currentPage}</span>/&nbsp;${allPage} </span>        
       </li>

       <!--    -->        
       <li><a href="javascript:void(0)" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" onclick="queryRequirListByPage(${allPage})">  </a></li>

       <!--          ,        , --> 
       <s:if test="#currentPage < #allPage">
        <li>
         <a href="javascript:void(0)" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" aria-label="Next" onclick="queryRequirListByPage(${currentPage+1})">
         <span aria-hidden="true">&raquo;</span>
         </a>
        </li>
       </s:if>
       <li>
        <span class="skipPageSpan">    &nbsp;
        <select onchange="selectPage(this)">
         <s:iterator var="lst" begin="1" end="#allPage" step="1">          
          <s:if test="%{#lst == #currentPage}">
           <option selected="selected" value="<s:property/>" ><s:property/></option>  
           </s:if>
           <s:else>
            <option value="<s:property/>" ><s:property/></option>
           </s:else>
         </s:iterator>                    
        </select>
        &nbsp; 
        </span>
        </li>

       </ul>
      </nav>

     </div>      


     </div>     




 <hr/>

</body>
</html>

action

 //      
 public String queryRequirListByPage(){
  int pageSize=5;//    
  String hql="select r from Requirement r where r.reStatus !=2 ";
  if(sortValue == null || sortValue.length() <= 0){
   hql=hql+"order by r.publishDatetime desc";
   ActionContext.getContext().put("sortValue", "publishDatetime"); //      
   session.put("sessionReqSortValue","publishDatetime");
  }else{
  hql=hql+"order by r."+sortValue+" desc";
   ActionContext.getContext().put("sortValue", sortValue); //      
   session.put("sessionReqSortValue",sortValue);
  }
  long icount=requirementService.countAllRe();//    
  long allPage;//   
  //       ,    ,   +1;
  if((icount%pageSize)==0){
   allPage=icount/pageSize;
  }
  else{
   allPage=(icount/pageSize)+1;
  }
  System.out.println("   :"+icount+";   :"+allPage+";    :"+pageNo);
  List<Requirement> requiList=requirementService.queryByPage(hql, pageNo, pageSize);
  ActionContext.getContext().put("requiList", requiList);//    
  ActionContext.getContext().put("icount", icount);//    
  ActionContext.getContext().put("allPage", allPage);//   
  ActionContext.getContext().put("currentPage", pageNo); //    
  session.put("sessionCurrentPage", pageNo);
  return "requireContent";

 }

service

  public long countAllRe() {
  return requirementDao.countAllRe();
 }
  public List<T> queryByPage(String hql, int pageNo, int pageSize) {
  return requirementDao.queryByPage(hql, pageNo, pageSize);
 }
dao

 //       ,          (   SSH)
 public long countAll() {
  List<?> l = getSession().createQuery("select count(*) from "
    + clazz.getSimpleName()).list();
  if (l != null && l.size() == 1 )
  {
   return (Long)l.get(0);
  }
  return 0;
 }
 public List<T> queryByPage(String hql, int pageNo, int pageSize) {
  return getSession()
    .createQuery(hql)
    .setFirstResult((pageNo - 1) * pageSize)
    .setMaxResults(pageSize)
    .list();
 }
이상 이 바로 본 고의 모든 내용 입 니 다.여러분 의 학습 에 도움 이 되 고 저 희 를 많이 응원 해 주 셨 으 면 좋 겠 습 니 다.

좋은 웹페이지 즐겨찾기