2012-04-20 95 views
0

我有上傳一個Excel文件的頁面。如果有錯誤,我使用顯示標籤以表格格式顯示這些錯誤。顯示標籤如何工作?

一切正常,直到顯示。但是,如果我必須對數據進行排序或導出,那麼它會再次停止工作,並且它會重定向到同一頁面,而沒有任何數據。

我猜對於每一個操作(如排序和導出),它都會觸及數據庫,因此在下一個請求中它不會顯示任何數據,因爲它沒有獲取文件名。

任何人都可以解釋我是對還是錯?我是這個顯示標籤的新手。

這裏是我的JSP代碼的src:

</head> 
<body> 
    <form:form id="formAdd" method="post" action="locationSave.do" 
     commandName="location"> 
     <form:hidden path="id" /> 
     <form:hidden path="isDeleted" /> 
     <form:hidden path="remarks" /> 
     <form:hidden path="status" /> 
     <form:hidden path="updatedDt" /> 
     <input type="hidden" value="${locationCodes}" id="codes"> 

     <table style="width: 1000px; border:0; cellspacing:1; cellpadding=0; class=table_border; align :center;"> 
     <tr> 
      <td colspan="6" class ="H1"> 
       Location Master 
      </td> 
     </tr> 
     <tr> 
      <td colspan="6" class="H2"> 
       Add Location 
      </td> 
     </tr>  
     <tr> 
       <td style="width: 16%;" class ="tdheader_left"><form:label path="code"> 
         <spring:message code="label.loccode" /> 
        </form:label></td> 
       <td style="width: 16%;" class="tdheader_textbox"><form:input 
         path="code" accesskey="o" cssClass="input" size="7" maxlength="5" 
         id="code" /></td> 

       <td style="width: 16%;" class ="tdheader_left"><form:label path="name"> 
         <spring:message code="label.locname" /> 
        </form:label></td> 
       <td style="width: 16%;" class="tdheader_textbox"><form:input 
         path="name" accesskey="n" class="input" maxlength="20" size="25" 
         id="name" /></td> 

       <td style="width: 16%;" class ="tdheader_left"><form:label path="locGrp"> 
         <spring:message code="label.locGrp" /> 
        </form:label></td> 
       <td style="width: 16%;" class="tdheader_dropdown"><form:select accesskey="g" 
         path="locGrp.id" class="input" id="grpId"> 
         <form:option value="-1" label="--- Select ---" /> 
         <form:options items="${locGrp}" /> 
        </form:select></td> 
      </tr> 
      <tr> 
       <td colspan="6" align="center" class="H1"> 
       <input id="save" accesskey="s" type="submit" value="Save"/> 
       <input id="reset" accesskey="r" type="reset" value="Reset" /> 
       <input type="button" accesskey="c" value="Cancel" onclick="window.location = 'location.do';" /> 
       <input type="button" id="upload_file" 
        accesskey="a" value="Upload File" 
        /></td> 
      </tr> 
     </table> 
    </form:form> 



    <div id="formUpload" style="text-align:center;display:block;"> 
    <form:form id="formFile" method="post" action="locationFileUpload.do" commandName="file" enctype="multipart/form-data"> 
     Please select a file to upload : <input type="file" name="file" /> 
     <input type="submit" value="upload" id="success" /> 
     <c:if test="${locErrorList != null}"> 
    <div id="uploaderror"> 
    Following locations could not be uploaded 
     <display:table uid="2" name="locErrorList" class="displaytag" id="locError" pagesize="10" excludedParams="*" requestURIcontext="true" 
      defaultorder="ascending" requestURI="locationFileUpload.do" export="true" > 
      <display:column property="code" sortable="true" title="Location Code" headerClass="sortable" /> 
      <display:column property="name" sortable="true" title="Location Name" headerClass="sortable" /> 
      <display:column property="error" sortable="true" title="Reason For Failure" headerClass="sortable" />   
    </display:table> 
    </div> 
    </c:if> 
     </form:form> 

     </div> 

</body> 
</html> 

回答

0

由displaytag產生的排序和分頁鏈接具有相同的請求參數在顯示錶中的請求而發送的人。所以,如果你發佈形式與請求參數foo=1bar=2,並顯示一個表作爲這一請求提交的結果,生成的鏈接將具有href看起來像這樣:

<a href="theRequestURI?foo=1&bar=2&d-..."> 

所以,當你點擊在鏈接上,您將向您的服務器發送一個新請求,並且此請求應使用發送的參數來取回要顯示的數據列表並使它們可供JSP訪問。 JSP中的顯示標籤將重新生成表格,並使用displaytag特定參數(以d-開頭的參數)對數據進行排序並僅顯示適當的頁面。