【问题标题】:Show a 'Please wait' alert on JSP when button is clicked. when the processing is complete on servlet, remove the alert单击按钮时在 JSP 上显示“请稍候”警报。当 servlet 上的处理完成时,删除警报
【发布时间】:2016-11-06 08:00:51
【问题描述】:

我的 JSP 页面 onDownload 函数调用一个 servlet,函数如下。我想在单击下载按钮时显示“请稍候”警报。当 servlet 处理完成后,关闭警报。

JSP 代码:

    function onDownload(){
        var dType = 'download';
        var url = "<%=strDownloadURLTest%>"+"/downloadservlet?downloadType="+dType+"&PNumber="+'<%=custPNo%>';
        document.getElementById('downloadP').href = url;
        document.getElementById('downloadP').target='_blank';
    }

Servlet 端处理,代码:

        byte content[]=null;
    try
    {   GetPDAO getPDAO= new GetPDAO();

          for(int i=0;i<5;i++)
          {
              content=getPDAO.getPFromEb( strPN);
               DateFormat df = new SimpleDateFormat("dd/MM/yy HH:mm:ss");
               Date dateobj = new Date();
             content=null;
             if(content==null) 

              {  
                 Thread.sleep(5000);

             }
             else {
                 content=getPDAO.getPFromEb( strPN);
                 break;
             }
          }

【问题讨论】:

    标签: java jquery ajax jsp servlets


    【解决方案1】:

    最后我同意使用 AJAX(在我没有找到其他方法之后)从 servlet 获得响应,如下所示。但是我是第一次使用 AJAX。我在我的 JSP 中添加了以下代码,并且 servlet 代码与以前相同。请建议是否正确完成?

    $.ajax({
        type: 'post',
        url: '"<%=strDownloadURLTest%>"+"/downloaddocservlet?downloadType="+dType+"&PNumber="+"<%=custPNo%>"',
        data: {
            name: $('#dType').val()
        },
        beforeSend:function(){
        alert("Please wait.....");
            // this is where we append a loading image
        },
        success:function(responseText){
        alert.close();
            // successful request; do something with the data            
        },
        error:function(){
            // failed request; give feedback to user
        }
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-11-15
      • 1970-01-01
      • 2015-07-15
      • 2018-04-06
      • 1970-01-01
      • 2023-02-06
      • 2018-05-01
      • 2021-01-18
      相关资源
      最近更新 更多