Servlet不转发到jsp

时间:2016-10-18 06:34:15

标签: java ajax jsp servlets

我有几个JSP:home和graph。

我使用ajax:ExcelServlet从主JSP调用servlet。

我需要从servlet转发到图JSP。

我能够控制Servlet,所以映射和ajax调用都没问题。

然而,这种情况并没有发生。

针对home.jsp:

   $.ajax({
            type: "get",
            url: "CopyServlet",
            beforeSend:function(){
                $('#text3').css({"color":"red"});
                $('#text3').text("Running Dynamic Diff Graph");
            },
            success:function(responseText){
                $('#text3').css({"color":"green"});
                $('#text3').text(responseText);
            },
            complete:function(){
                $.ajax({
                        type: "post",
                        url: "ExcelServlet",
                        beforeSend:function(){
                            $('#text4').css({"color":"red"});
                            $('#text4').text("Preparing Difference Summary");
                        },
                        success:function(data){}
                });
            }
   });

Excelservlet:

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        ExcelExtract excelextract = new ExcelExtract();
        excelextract.extract();

        String newDup=excelextract.getNewDup();
        request.setAttribute("newDup", newDup);
        String diff=excelextract.getDiff();
        request.setAttribute("diff", diff);
        String newRecNA=excelextract.getNewRecNA();
        request.setAttribute("newRecNA", newRecNA);
        String oldRecNA=excelextract.getOldRecNA();
        request.setAttribute("oldRecNA", oldRecNA);
        String unchangedRec=excelextract.getUnchangedRec();
        request.setAttribute("unchangedRec", unchangedRec);
        if (diff.equals("0.0")){
            request.setAttribute("message", "Test Passed: 0 differences");
        }
        else{
            request.setAttribute("message", "Test Failed: Differences found");
        }
        request.getRequestDispatcher("graph.jsp").forward(request, response);
    }

graph.jsp

<body>
    <div align="center">
    <h1>Welcome to ETL Automation Testing Tool</h1>
    <br>
    <table border="1">

    <th align="center"><b>Difference summary:</b></th>
    <tr><td>${oldFile}</td></tr>
    <tr><td>${newFile}</td></tr>
    <tr><td>${dml}</td></tr>
    <tr align="center"><td><b>Counts:</b></td></tr>
    <tr>
    <td>Old Records:</td>
    <td>${oldRec}</td>
    </tr>
    <tr>
    <td>Old Duplicates:</td>
    <td>${oldDup}</td>
    </tr>
    <tr>
    <td>New Records:</td>
    <td>${newRec}</td>
    </tr>
    <tr>
    <td>New Duplicates:</td>
    <td>${newDup}</td>
    </tr>
    <tr>
    <td>Differences:</td>
    <td>${diff}</td>
    </tr>
    <tr>
    <td>New Records not in old(Adds):</td>
    <td>${newRecNA}</td>
    </tr>
    <tr>
    <td>Old Records not in new(Deletes):</td>
    <td>${oldRecNA}</td>
    </tr>
    <tr>
    <td>Unchanged Records:</td>
    <td>${unchangedRec}</td>
    </tr>
    </table>
    <h3>${message}</h3>
        </div>
</body>

0 个答案:

没有答案