如何在IE调试控制台中显示servlet运行时?

时间:2017-05-26 00:41:48

标签: javascript java jsp servlets

我有以下JSP代码,我可以查看javascript代码的运行时间,但我无法检查servlet进程的运行时间,runTime始终为0,我该怎么办?

<%@ page contentType="text/html; charset=UTF-8"%>
<%@ page import="java.util.List"%>
<%@ page import="java.util.ArrayList"%>
<%
    long startTime = System.currentTimeMillis();
    MyForm myForm = (MyForm) request.getAttribute(ACTION_FORM_KEY);
    if(myForm == null) {
        myForm = new PsiSearchForm();
    }

    List<Object> myList = myForm.getMyList();
    if(myList == null) {
        myList = new ArrayList<Object>();
    }
    long endTime = System.currentTimeMillis();
    long runTime = endTime - startTime;
%>
<html>
    ...
</form>
</body>
<script language="JavaScript" type="text/JavaScript">
    console.time('my_form.jsp');
    // javascript process
    console.timeEnd('my_form.jsp');
    console.log("Select My List time: " + <%=runTime%>);
</script>
</html>

1 个答案:

答案 0 :(得分:3)

尝试使用System.nanoTime();

来自Oracle

   long startTime = System.nanoTime();
   // ... the code being measured ...
   long estimatedTime = System.nanoTime() - startTime;