简体   繁体   English

如何在Spring + JSP中查看发送请求和获取响应之间的时差

[英]How to see the time difference between sending request and getting response in Spring+JSP

I struck in this part of my code. 我触及了这部分代码。

I am using Spring+Hibernate to fetch records from database and JSP to view those records. 我正在使用Spring + Hibernate从数据库和JSP中获取记录以查看这些记录。

The problem here is it is taking almost 10sec to display 500 records :( 这里的问题是它需要将近10秒来显示500条记录:(

So,I kept some timestamps to see where it is taking moretime. 所以,我保留了一些时间戳,看看它花了多长时间。

I found some Interesting things : 我找到了一些有趣的东西:

1.To go from jsp page to DAO where I have code to fetch records it is taking more time(dont know exatly how much time it is taking) 1.从jsp页面转到DAO,我有代码来获取记录,这需要更多的时间(不知道它花了多少时间)

2.To fetch records from database it is taking milliseconds 2.要从数据库中获取记录,需要几毫秒

3.Do dispaly them back to jsp it is taking 3seconds. 3.将它们显示回jsp需要3秒钟。

My Question is how to find the time in first case.I successfully find time in remaining two cases. 我的问题是如何在第一种情况下找到时间。我在剩下的两个案例中成功找到了时间。

so,I put Timestamp in JSP 所以,我把时间戳放在JSP中

   <c:if test="${currentPage != 1}">
   <a onclick="return displayTimeFunctionP();" class="button" href="pagination.html?  page=${currentpage-1}">  &lt;&lt; Previous </a>
</c:if>

javascript : javascript:

function displayTimeFunctionP() {

<% Timestamp t1 = new Timestamp(new Date().getTime());%>
<%System.out.println("Time stamp in onclick() function[previous] :"+t1); %>  

return false(true also I tested);

} }

But it is not displaying time in this page and directly goes to next page and then it is displaying time.But,I function is executing because if I give return false it is not going to next page and not displaying anything. 但是它没有在这个页面中显示时间并且直接进入下一页然后显示时间。但是,我的函数正在执行,因为如果我给出返回false,它不会进入下一页而不显示任何内容。

Why it is happening and how to get timestamp from that javascript before going to next page? 为什么会发生这种情况以及如何在进入下一页之前从该javascript获取时间戳?

Please help.... 请帮忙....

This block of java code prints the date into the JS function 这段java代码将日期打印到JS函数中

function displayTimeFunctionP() {
  <% Timestamp t1 = new Timestamp(new Date().getTime());%>
  <%System.out.println("Time stamp in onclick() function[previous] :"+t1); %>  
  return false;
}

Is resolved as: 被解决为:

function displayTimeFunctionP() { 
  return false;
}

And prints into your server system out: Time stamp in onclick() function[previous] 23423424234 Not into your page. 并打印到您的服务器系统中: onclick()函数中的时间戳[上一页] 23423424234不在您的页面中。

Also after executing the onclick it does the href navigation and changes the page. 在执行onclick之后,它还会执行href导航并更改页面。

To print in the web page you should use out.println (Without System) but if you print the text directly into the JS function it makes a javascript error. 要在网页中打印,你应该使用out.println (没有系统),但如果你直接将文本打印到JS函数中,则会出现javascript错误。 And this not stop the navigator to load the next page. 这并不能阻止导航器加载下一页。 You should use javascript "document" or DOM to print the text in someplace. 您应该使用javascript“document”或DOM在某个地方打印文本。

try this : First in your html or in jsp define like this : 试试这个:首先在你的html或jsp中定义如下:

<p id="demo"></p>

And add the following script : 并添加以下脚本:

 <script>
    function myFunction() {
      var d = new Date();
      document.getElementById("demo").innerHTML = d ;
    }
</script>

If you want to print milliseconds try 如果要打印毫秒,请尝试

d.getMilliseconds()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM