使用ajax

时间:2019-04-24 11:55:20

标签: ajax servlets

我有一个正在动态创建的表。我正在使用图像预览操作的表格的最后一个单元格。为此,我编写了一个像这样的servlet。

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        String docpath = request.getParameter("filename");
        String docname = request.getParameter("filepath");
        System.out.println(docpath);
        try {
            File original=new File(docpath);
            File dest=new File("T:\\Temp\\");
            FileUtils.copyFileToDirectory(original, dest);
            String newPath="T:\\Temp\\"+docname;
            request.getSession().setAttribute("newPath", newPath);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        RequestDispatcher rd=request.getRequestDispatcher("index.jsp");
        rd.forward(request, response);
    }

}

我正在使用此ajax方法创建表。然后,我在另一个ajax方法中发布servlet参数。然后,我想从servlet返回新值。

<script>
if($.fn.dataTable.isDataTable( '#example' )){
    var table = $('#example').DataTable();
}
function getData(){

    $('#example tbody').html('');
    var URL_PREFIX="http://localhost:8983/solr/archiveCore/select?q=strSO_copy:";
    var URL_MIDDLE="AND PackName_copy:";
    var URL_SUFFIX="AND DocType_copy:";
    var strSO="\"" + $("#ngramBoxstrSO").val() + "\"";
    var PackName="\"" + $("#ngramBoxPackName").val() + "\"";
    var DocType="\"" + $("#ngramBoxDocType").val() +"\"";
    var URL=URL_PREFIX + strSO + URL_MIDDLE + PackName + URL_SUFFIX + DocType;
    $.ajax({
        url:URL,
        dataType:'jsonp',
        jsonp : 'json.wrf',
        type :'get',
        cache :false,
        success: function(data){
            var docs=data.response.docs;
            var html='';        
            $.each(docs,function(key,value){
                var arrayExtensions=['jpg','JPG','JPG File','jpeg','JPEG image','PNG','TIFF image','tiff'];
                $.ajax({
                    type:'post',
                    url:'copyImage',
                    data:{filename:value.FileName,filepath:value.FilePath},
                    dataType:'jsonp',
                    success:function(data){
                        $(this).find('#showImages').src=data;
                    }
                });
                html+='<tr>';
                html+='<td>'+value.id+'</td>';
                html+='<td>'+value.strSO+'</td>';
                html+='<td class="text-center">'+value.PackName+'</td>';
                html+='<td class="text-center">'+value.DocType+'</td>';
                html+='<td class="text-center">'+value.DocName+'</td>';
                html+='<td class="text-center"><form method="POST" action="openDocumentServlet" target="_blank"><input name="document" value="'+value.FilePath+'" hidden><input name="docName" value="'+value.FileName+'" hidden><input id="buton" type="submit"  class="btn btn-sm" value="OPEN"></form></td>';
                html+='<td class="text-center"><input name="filename" value="'+value.FilePath+'" hidden><input name="filepath" value="'+value.FileName+'" hidden><a href="#" class="preview"><input type="image" id="imageButton" src="images//SoftwareIcons-21-512.png" style="width:50px;height:50px;"><img id="showImages" src="" class="hide-image"/></a></td>';
                html+='</tr>';
            });

            $('#example').DataTable().destroy();
            $('#example tbody').html(html);
            var table=$('#example').DataTable({
                "aaSorting" : [],

            });
        },
    });


};
</script>

当我运行项目时,它会给我这个错误。

null
null
null
null
Apr 24, 2019 2:20:36 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [org.solr.copyImage] in context with path [/CorroLog] threw exception
java.lang.NullPointerException
    at java.io.File.<init>(Unknown Source)
    at org.solr.copyImage.doPost(copyImage.java:56)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:661)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:493)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:650)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:800)
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:806)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1498)
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Unknown Source)

此邮递区号有什么问题?我如何解决它?谢谢。

0 个答案:

没有答案