程序控制从Ajax返回到servlet

时间:2015-10-13 06:10:36

标签: javascript java jquery ajax servlets

我们必须在没有页面刷新的情况下从后端到网页显示某些文本,我们使用Javascript / ajax相同,其中一个链接成功,所以我们在其他地方尝试了相同的逻辑,打印发生在网页上但是我们在几秒钟内得到一个空白屏幕,上面写着“服务于:/”。 在几秒钟内,网页和后端所需的文本将消失为空白屏幕。

的Ajax:

$(document).ready(function() {
$('#ViewCubeConfigBookingsCube').click(function() {
  var Stream = "BookingsCubeStage";
   $.ajax({
type:'POST',    
url: "ViewCurrentCubeConfig",
data: {Stream: Stream},
cache: false,
success: function(result) {
/*result_without_path = result.replace("Served at: /FINBI_E2E ","");*/
$("#data").html(result);
$("#data").html(result).slideDown('fast');
 }
});
});
});

的Servlet

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub
    doGet(request, response);
    String Stream=request.getParameter("Stream");
    String ConfigXMLPath=UtilLib.getEnvVar("CubeConfigXMLFilePath");
    String ConfigDetails="";
    response.setContentType("text/html");
    response.setCharacterEncoding("UTF-8");
    @SuppressWarnings({ })
    HashMap CurrentConfigDetails =new HashMap();
    System.out.println("The Stream is: "+Stream);
    ViewCurrentCubeConfig_Implementation ViewCurrCubeConfig =new ViewCurrentCubeConfig_Implementation();
    CurrentConfigDetails=ViewCurrCubeConfig.ViewCurrentCubeConfig(ConfigXMLPath,Stream);

      // Get a set of the entries
      Set set = CurrentConfigDetails.entrySet();
      // Get an iterator
      Iterator i = set.iterator();
      // Display elements

      while(i.hasNext()) {
         Map.Entry me = (Map.Entry)i.next();
         //System.out.print(me.getKey() + ": ");
         //System.out.println(me.getValue());
         ConfigDetails=ConfigDetails+(me.getKey() + ": ");
         ConfigDetails=ConfigDetails+" "+(me.getValue());
         ConfigDetails=ConfigDetails+"\n";  
      }
     // System.out.println("Config detailas are as : "+ConfigDetails);
      try{
          PrintWriter out =response.getWriter();
              out.print(ConfigDetails);
      }
      catch(Exception e){
          e.printStackTrace();
      } }

Devtools Search results

点击之前: enter image description here

配置输出:

  

Config detailas如下:年份:FY15   数据库:ZZZZZ   申请:YYYYY   NumberOfMonths:5   ServerName:XXXXX   MonthStartingFrom:Aug

HTML:

 <a href="" id="ViewCubeConfigBookingsCube">View Current Config  Details</a><br>
 <div id="showBookingsCubeCurrConfig"></div> 

0 个答案:

没有答案