显示标签如何工作?

时间:2012-04-20 14:03:39

标签: jsp jsp-tags displaytag

我有一个页面,我上传了一个Excel文件。如果有错误,我会使用display tag以表格格式显示这些错误。

一切正常,直到显示。但是,如果我必须对数据进行排序或导出,那么它将再次停止工作,并且重定向到同一页面而没有任何数据。

我想对于每个操作(如排序和导出)它都会访问数据库,因此在下一个请求时它没有显示任何数据,因为它没有获取文件名。

有人可以解释我是对还是错?我是这个显示标签的新手。

这是我的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>

1 个答案:

答案 0 :(得分:0)

displaytag生成的sort和分页链接与显示表的请求中发送的请求参数具有相同的请求参数。因此,如果您发布包含请求参数foo=1bar=2的表单,并显示一个表作为此请求提交的结果,则生成的链接将具有如下所示的href:

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

因此,当您单击链接时,您将向服务器发送新请求,此请求应使用发送的参数来获取要显示的数据列表,并使JSP可以访问它们。 JSP中的display标签将重新生成表,并使用特定于displaytag的参数(以d-开头的参数)对数据进行排序并仅显示相应的页面。

相关问题