如何在操作类中识别两个不同的 JSP 页面按钮?如何基于 JSP 页面视图按钮和查看全部按钮编写条件

how to identify two different jsp page buttons in action class?how to write the condition, based on jsp page View button and view All Button?

本文关键字:按钮 JSP 何基于 视图 条件 全部 操作 识别 两个      更新时间:2023-09-26

文件名是ScanorAttach.jsp- 此文件包含查看全部按钮。 注意 - 我正在导入结果.jsp。

<c:if test="${not empty scanForm.results1 || not empty scanForm.results2}">
<input type="button" value="View All"  class="button float-right" onclick="showDocuments('')"/>
</c:if>
<tr>
<td>
 <c:import url="/jsp/common/scan/results.jsp"/></td>
</tr>

结果.jsp - 此文件包含"查看"按钮

 <c:forEach var="result" items="${scanForm.results1}" varStatus="status">
                            <tr class="${zebra}">
                                <td>${result.documentName}</td>
                                <c:if test="${empty scanForm.documentId && loginuser.role.roleDesc eq 'Admin'}">
                                    <td>${result.screenName}</td>
                                </c:if>
                                <td>
                                    <c:choose>
                                        <c:when test="${empty scanForm.documentId && loginuser.role.roleDesc eq 'Admin'}">
                                            <img src="${path}/images/edit.png" title="Edit" onclick="editDocument('${result.id}');"/>
                                            <img src="${path}/images/trash.png" title="Delete" onclick="removeDocument('${result.documentName}', '${result.id}');"/>
                                        </c:when>
                                        <c:otherwise>
                                            <c:if test="${not (roleDuty.viewAccountingScanAttach
                                                              && (scanForm.screenName eq 'INVOICE' || scanForm.screenName eq 'AR BATCH'))}">
                                                  <img src="${path}/images/icons/scanner.png" title="Scan" onclick="showComment('${result.documentName}', 'Scan');"/>
                                                  <img src="${path}/images/icons/attach.png" title="Attach" onclick="showComment('${result.documentName}', 'Attach');"/>
                                            </c:if>
                                        <img src="${path}/images/icons/preview.png" title="View" onclick="showDocuments('${result.documentName}')"/> 
                                            <c:if test="${result.uploadCount > 0}">
                                                <span class="red-90" style="vertical-align: super">
                                                    (${result.uploadCount})
                                                </span>
                                            </c:if>
                                        </c:otherwise>
                                    </c:choose>
                                </td>
                            </tr>
                        </c:forEach>

例如,我有 2 份文件预订和照片。 如果我单击查看(预订)按钮,则会查看特定文档(仅限预订)。 如果我单击"查看全部"按钮,则应显示所有文件(预订和照片)。文件名 -文档.jsp

<div class="results-container">
<table width="100%" cellpadding="0" cellspacing="1" class="display-table" id="filelist">
    <thead>
        <tr>
            <th><a href="javascript:doSort('documentName')">Document Name</a></th>
            <th><a href="javascript:doSort('fileName')">File Name</a></th>
            <th><a href="javascript:doSort('fileSize')">File Size</a></th>
            <th><a href="javascript:doSort('operation')">Operation</a></th>
            <th><a href="javascript:doSort('operationDate')">Operation Date</a></th>
            <th><a href="javascript:doSort('status')">Status</a></th>
            <th><a href="javascript:doSort('comment')">Comments</a></th>
            <th>Action</th>
        </tr>
    </thead>
    <tbody>
        <c:set var="zebra" value="odd"/>
        <c:forEach var="result" items="${scanForm.results}" varStatus="status">
            <tr class="${zebra}">
                <td>${result.documentName}</td>
                <td>${result.fileName}</td>
                <td>${result.fileSize}</td>
                <td>${result.operation}</td>
                <td>${result.operationDate}</td>
                <td class="receivedMasterStatus${status.index}">${result.status}</td>
                <td>${str:splitter(result.comments, 75, '<br/>')}</td>
                <td>
                    <img src="${path}/images/icons/preview.png"
                          title="View" onclick="viewDocument('${result.fileName}', '${result.fileLocation}/${result.fileName}')"/>
                    <c:choose>
                        <c:when test="${roleDuty.deleteAttachedDocuments eq 'true' && not empty results3}">
                           <img src="${path}/images/trash.png"
                                 title="Delete" onclick="deleteDocumentSop('${result.id}', '${result.fileName}', '${result.documentName}')"/>
                        </c:when>
                        <c:otherwise>                                
                            <c:if test="${roleDuty.deleteAttachedDocuments eq 'true'}">
                                    <img src="${path}/images/trash.png"
                                     title="Delete" onclick="deleteDocument('${result.id}', '${result.fileName}', '${result.documentName}')"/>
                            </c:if>
                        </c:otherwise>
                    </c:choose>
                </td>
            </tr>

操作类名称 - 扫描操作.jsp

 public ActionForward showDocuments(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
    ScanForm scanForm = (ScanForm) form;
    if (CommonUtils.isNotEmpty(scanForm.getScreenName())) {
        List<ResultModel> results = new ScanDAO().getDocuments(scanForm.getScreenName(), scanForm.getDocumentName(), scanForm.getDocumentId());
        scanForm.setResults(results);
    }
    request.setAttribute("results3", request.getSession().getAttribute("results3"));
    return mapping.findForward(DOCUMENTS);
}
public ActionForward deleteDocument(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
    ScanForm scanForm = (ScanForm) form;
    DocumentStoreLogDAO documentDAO = new DocumentStoreLogDAO();
    DocumentStoreLog document = documentDAO.findById(scanForm.getId());
    File file = new File(document.getFileLocation(), document.getFileName());
    if (file.exists()) {
        file.delete();
    }
    request.setAttribute("message", document.getFileName() + " is deleted successfully");
    documentDAO.delete(document);
  //   scanForm.setDocumentName(""); here i want to write condition and also how to differentiate view and View All Button. 
    return showDocuments(mapping, form, request, response);
}

该列表无法正常工作。预订包含 2 个文件。照片包含 3 个文件.如果我在预订中删除 1 个文件,删除后仅显示一个文件。在我的项目中,它显示了所有文件(照片文件也),我想你被理解了。提前谢谢你

if(request.getParameter("viewAll.x") != null){ <br>
}else if(request.getParameter("view.x") != null){ <br>
}

在操作类中,您可以检查用户是否单击了每个按钮。