如何在jsp端显示加载消息,如“请稍候”?

时间:2015-11-25 13:10:18

标签: javascript java jsp extjs

基本上我想在执行某个进程时显示“请稍候”加载消息。我尝试了很多ext js但它不起作用。      在这里,我正在使用我的jsp代码以及js代码。

这是我的JS文件。

<div class="wrapper row">
    <?php
    define('WP_USE_THEMES', false);
    require('news/wp-load.php');
    query_posts('showposts=3');

    $isFirst = true;
    while (have_posts()): the_post();
    if($isFirst == true) {
        echo '<div class="col-sm-6">';
        $isFirst = false;
    } else {
        echo '<div class="col-sm-4">';
    }
    ?><h2><?php the_title(); ?></h2>
    <p><em>Posted <?php the_date(); ?> by <?php the_author(); ?></em></p>
    <div class="image"><?php
        if ( has_post_thumbnail() )
            the_post_thumbnail( 'thumbnail' );
        else
            echo '<img src="news/wp-content/uploads/2015/06/150x150-2.jpg" alt="Example Image" title="Example" width="100px"/>';
        ?></div>
        <p><?php the_excerpt(); ?></p>
        <p><a href="<?php the_permalink(); ?>">Read more...</a></p>
    </div><!-- /.col-sm-4 -->
<?php endwhile; ?>
</div>

这是我的JSP文件。

exportIFrame = document.createElement('iframe');
                                exportIFrame.src = "about:blank";
                                exportIFrame.width = "2px";
                                exportIFrame.height = "2px";
                                exportIFrame.style.border = 0;
                                exportIFrame.id = "loginFrame";
                                exportIFrame.name = "loginFrame";

                                document.body.appendChild(exportIFrame);

                                var idocument = exportIFrame.contentWindow.document;

                                loginForm = idocument.createElement("form");
                                loginForm.setAttribute("target", "loginFrame");
                                loginForm.setAttribute("method","Post"); 
                                loginForm.setAttribute("action","./DeliveryTech/services/GenericExportGridDataToExcel.jsp");  

                                var hiddenFieldsearchConditions = idocument.createElement("input");
                                hiddenFieldsearchConditions.setAttribute('type',"hidden");
                                hiddenFieldsearchConditions.setAttribute('name',"searchConditions");
                                hiddenFieldsearchConditions.setAttribute('value',searchConditions);
                                loginForm.appendChild(hiddenFieldsearchConditions);

                                var hiddenFieldGridName = idocument.createElement("input");
                                hiddenFieldGridName.setAttribute('type',"hidden");
                                hiddenFieldGridName.setAttribute('name',"gridName");
                                hiddenFieldGridName.setAttribute('value',gridName);
                                loginForm.appendChild(hiddenFieldGridName);

                                var hiddenFieldVisibleColumn = idocument.createElement("input");
                                hiddenFieldVisibleColumn.setAttribute('type',"hidden");
                                hiddenFieldVisibleColumn.setAttribute('name',"visibleColumn");
                                hiddenFieldVisibleColumn.setAttribute('value',Ext.util.JSON.encode(visibleColumn)); 
                                loginForm.appendChild(hiddenFieldVisibleColumn);

                                var hiddenFieldFROM = idocument.createElement("input");
                                hiddenFieldFROM.setAttribute('type',"hidden");
                                hiddenFieldFROM.setAttribute('name',"pagefrom");
                                hiddenFieldFROM.setAttribute('value',pageFrom);
                                loginForm.appendChild(hiddenFieldFROM);

                                var hiddenFieldTO = idocument.createElement("input");
                                hiddenFieldTO.setAttribute('type',"hidden");
                                hiddenFieldTO.setAttribute('name',"pageto");
                                hiddenFieldTO.setAttribute('value',pageTo);
                                loginForm.appendChild(hiddenFieldTO);

                                exportIFrame.appendChild(loginForm);
                                loginForm.submit(); 

请关注<% %> <script language="javascript"> loadMask = new Ext.LoadMask(Ext.getBody(), {msg:"Please wait..."}); loadMask.show(); </script> <% CommonLogger.getLogger().info("\n\nGenericExportGridDataToExcel.jsp: [START]"); String userId = ""; if(null!=bizSite && null!=bizSite.getCurrentUser()){ userId = bizSite.getCurrentUser(); CommonLogger.getLogger().info("\nGenericExportGridDataToExcel.jsp: userId:"+userId); } else { CommonLogger.getLogger().info("\nSession is Expired:"); } //Block for User permissions on and Owning offices JSONObject userPermissions = null; JSONArray userPermissionsArr = null; List<String> userAllowDashboards = new ArrayList<String>(); GlobalOrderEntryService globalOrderEntryService = new GlobalOrderEntryServiceImpl(); if(null == session.getAttribute("SDIUserDashOwningOffices")) { userPermissions = globalOrderEntryService.getUserPermissionAccessLevel(userId).getJSONObject("data"); session.setAttribute("SDIUserDashOwningOffices", userPermissions); Iterator<?> userPermissionsKeys = userPermissions.keys(); while( userPermissionsKeys.hasNext() ){ String userPermKey = (String)userPermissionsKeys.next(); userAllowDashboards.add(Constants.DASHBOARD_NAMES_MAP.get(userPermKey)); } session.setAttribute("SDIUserDashboards", userAllowDashboards); } else { userPermissions = JSONObject.fromObject(session.getAttribute("SDIUserDashOwningOffices")); userAllowDashboards = JSONArray.fromObject(session.getAttribute("SDIUserDashboards")); } String owningOffices=""; Object ownOffcObj = userPermissions.get(Constants.DELIVERY_TECHNICIANS_PERMISSION_STR); if(null != ownOffcObj) { owningOffices = ownOffcObj.toString(); owningOffices = owningOffices.replaceAll("\\[","").replaceAll("\\]","").replaceAll(", ", ",").replaceAll("\"",""); } //Block for User permissions on and Owning offices Boolean totalRecordLimitExceed = false; int pageFrom =0,pageTO=0,firstResult=1,maxResult=1; DateFormat format = new SimpleDateFormat("dd-MM-yyyy"); String timeStamp = format.format(new Date()); //SearchFilterParser filterParser = new SearchFilterParserImpl(); //String searchConditions = request.getParameter("searchConditions"); Properties subtitleProperties = null; subtitleProperties = new Properties(); ClassLoader cl = Config.class.getClassLoader(); subtitleProperties.load(cl.getResourceAsStream("Subtitling.properties")); int perPageLimit = Integer.parseInt(subtitleProperties.getProperty(Constants.DELIVERY_TECH_EXPORT_TO_EXCEL_PAGE_LIMIT)); int totalRecordLimit = Integer.parseInt(subtitleProperties.getProperty(Constants.DELIVERY_TECH_EXPORT_TO_EXCEL_DATA_LIMIT)); String gridName = ""; if(null!=request.getParameter("gridName")) gridName = request.getParameter("gridName"); if(null!=request.getParameter("pagefrom")) pageFrom = Integer.parseInt(request.getParameter("pagefrom")); if(null!=request.getParameter("pageto")) pageTO = Integer.parseInt(request.getParameter("pageto")); LinkedHashMap<String,String> visibleColumnMap = new LinkedHashMap<String,String>(); JSONArray visibleColumns = null; JSONObject columnObj = null; if(null!=request.getParameter("visibleColumn")){ visibleColumns = JSONArray.fromObject(request.getParameter("visibleColumn")); for(int index = 0;index < visibleColumns.size();index++){ columnObj = visibleColumns.getJSONObject(index); visibleColumnMap.put(columnObj.getString("dataindex"),columnObj.getString("header")); } } String excelName = null; Map<String,Object> map = null; Map<String,Object> searchMap = null; GridParams gridParams = null; Map<String,Object> eqSearchConditions = null; Map<String,Object> neSearchConditions = null; String searchFor; try { CommonLogger.getLogger().info("\nGenericExportGridDataToExcel.jsp: perPageLimit:"+perPageLimit +"\t totalRecordLimit:"+totalRecordLimit); CommonLogger.getLogger().info("\nGenericExportGridDataToExcel.jsp: pageFrom:"+pageFrom +"\t pageTO:"+pageTO); if(pageFrom !=0 && pageTO != 0){ firstResult=pageFrom; if(pageFrom == pageTO){ maxResult = perPageLimit; }else if(pageTO > pageFrom){ maxResult = (((pageTO - pageFrom) +1 )* perPageLimit); } if(maxResult>totalRecordLimit){ totalRecordLimitExceed =true; } }else if(pageTO != 0){ firstResult=pageFrom; maxResult = pageTO; } CommonLogger.getLogger().info("\nGenericExportGridDataToExcel.jsp: firstResult:"+firstResult +"\t maxResult:"+maxResult); if(!totalRecordLimitExceed){ Map<String,Object> map1 = new HashMap<String,Object>(); map1.put(Constants.GRID_PARAMS_OBJECT_KEY,gridParams); HashMap<String,Object> searchConditions = new HashMap<String,Object>(); final String searchCondition; searchCondition=request.getParameter("searchConditions"); JSONArray searchConditionJSONArray = JSONArray.fromObject(request.getParameter("searchConditions")); JSONObject searchConditionJSONObject = null; map1.put(Constants.EQ_SEARCH_PARAMS_MAP_KEY,new HashMap<String,Object>(){{put("searchConditions",searchCondition);}}); if(map!=null){ gridParams = (map.get(Constants.GRID_PARAMS_OBJECT_KEY)!=null?((GridParams)map.get(Constants.GRID_PARAMS_OBJECT_KEY)):null); eqSearchConditions = (map.get(Constants.EQ_SEARCH_PARAMS_MAP_KEY)!=null?(Map<String, Object>)map.get(Constants.EQ_SEARCH_PARAMS_MAP_KEY):null); neSearchConditions = (map.get(Constants.NE_SEARCH_PARAMS_MAP_KEY)!=null?(Map<String, Object>)map.get(Constants.NE_SEARCH_PARAMS_MAP_KEY):null); } HSSFWorkbook wb = new HSSFWorkbook(); if(gridName!=null) { DeliveryTechServiceImpl deliveryTechDefaultService = new DeliveryTechServiceImpl(); if(Constants.DELIVERY_TECH_DEFAULTVIEW_GRIDNAME.equals(gridName)) { wb = deliveryTechDefaultService.exportToExcelDefaultView(map1,visibleColumnMap,"Default",owningOffices,firstResult,maxResult); excelName = Constants.DELIVERY_TECH_DEFAULTVIEW_EXCELNAME; }else if(Constants.DELIVERY_TECH_PLANINGVIEW_GRIDNAME.equals(gridName)) { wb = deliveryTechDefaultService.exportToExcelDefaultView(map1,visibleColumnMap,"Planing",owningOffices,firstResult,maxResult); excelName = Constants.DELIVERY_TECH_PLANINGVIEW_EXCELNAME; } } response.setContentType("application/vnd.ms-excel"); response.setHeader("Expires:", "0"); // eliminates browser caching response.setHeader("Content-Disposition", "attachment; filename="+excelName+"_"+timeStamp+".xls"); wb.write(response.getOutputStream()); response.getOutputStream().flush(); response.getOutputStream().close(); }else{ %> <script language="javascript"> loadMask.hide(); alert("Total record limit exceeded. Please enter valid page length."); </script> <% } %> <script language="javascript"> loadMask.hide(); </script> <% CommonLogger.getLogger().info("\n\nGenericExportGridDataToExcel.jsp: [END]"); } catch (Exception ex) { %> <script language="javascript"> loadMask.hide(); </script> <% CommonLogger.getLogger().info("\n\n Error in GenericExportGridDataToExcel.jsp"+ExceptionUtils.getFullStackTrace(ex)); //e.printStackTrace(); } %> 标记,而不是整个jsp代码。

3 个答案:

答案 0 :(得分:1)

如果我理解你的问题,我在使用jQuery / Ajax之前做了类似的事情。

我以这种方式实施:

JSP:

excel-vba

在JS中:

<div id="loading" style="background:url('<c:url value="path to your gif img"/>')50% 50% no-repeat rgb(249,249,249)">
    <label class="loading-msg">Please wait....</label>
</div>

你的CSS:

function beforeProcess() {
    $('#loading').show();
});

function afterProcess() {
    $('#loading').fadeOut(3000);
});

我不确定但您可以在流程之前调用这些函数,当流程完成(成功或失败)时,您可以隐藏/淡出元素。

答案 1 :(得分:0)

做一些关于AJAX的阅读。使用基于JSP的原生方式,我无法想到任何其他方式。

一般的想法是你会使用AJAX来调用需要一段时间的进程,在执行调用时呈现“Please Wait”消息。一旦调用完成执行,您就可以渲染输出。

编辑 - 对<script>标记的关注使我认为(如果这是一项任务)您应该使用AJAX调用来执行此操作。

答案 2 :(得分:0)

我可以看到你使用extjs。如果是这样,您可以随时使用

Ext.getCmp('yourelementid').setLoading(true);开始

Ext.getCmp('yourelementid').setLoading(false);停止

如果您的extjs布局已启动并运行,上述内容将非常方便。但是如果你想在jsp页面加载时显示加载掩码,那就是另一个故事了。如果是这种情况,请按以下步骤操作:

这是你在jsp文件中的html:

<body> <div id="loading-mask"></div> <div id="loading"> <div class="loading-indicator"> Loading .... </div>
</div> </body>

这是你的css:

#loading-mask {
  position: absolute;
  left:     0;
  top:      0;
  width:    100%;
  height:   100%;
  z-index:  20000;
  background-color: white;
}

#loading {
  position: absolute;
  left:     50%;
  top:      50%;
  padding:  2px;
  z-index:  20001;
  height:   auto;
  margin:   -35px 0 0 -30px;
}

#loading .loading-indicator {
  background: url(images/extanim32.gif) no-repeat; //just replace with an animated gif
  color:      #555;
  font:       bold 13px tahoma,arial,helvetica;
  padding:    8px 42px;
  margin:     0;
  text-align: center;
  height:     auto;
}

最后你的js:

 Ext.onReady(function() { 
          setTimeout(function(){
              Ext.get('loading').fadeOut({
              remove:true,
              easing: 'easeOut',
              duration: 2000
              });
              Ext.get('loading-mask').fadeOut({
              remove:true,
              easing: 'easeOut',
              duration: 2000
              });
            }, 250);
});