0

这是我的代码片段

这是我的 form.html

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>

    <h1>Beer Selection Page</h1>
    <form method="post" action="SelectBeer.do">
        Select beer characteristics
        <p>
            Color: <select name="color" size="1">

                <option value="light">light</option>
                <option value="amber">amber</option>
                <option value="brown">brown</option>
                <option value="dark">dark</option>
            </select> <br>
            <br>
            <input type="submit" value="Submit Beer" >

    </form>

    <form action="BandwidthCalc.do">
        <br>
        <br>
        <input type="submit" value="Calculate Bandwidth" >
    </form>

</body>
</html>

这是我的 BandwidthCalc.java servlet 类

public class BandwidthCalc extends HttpServlet {

    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException{

        RequestDispatcher view = request.getRequestDispatcher("bandwidth.jsp");
        view.forward(request, response);

    }
}

这是我的 bandwidth.jsp 文件

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Bandwidth calculation</title>
</head>
<body>

    This is bandwidth page!! <br>
    <script src="./js/jquery-2.1.3.min.js" type="text/javascript"></script>
    <script src="./Boomerang/boomerang.js" type="text/javascript"></script>
    <script src="./js/testBeacon.js" type="text/javascript"></script>

    <div id="results">
    </div>

</body>
</html>

这是我的 testBeacon.js 文件

var bw=null,be=null,lat=null,laterr=null;

BOOMR.init({
    user_ip: '127.0.0.1',

  });

    BOOMR.subscribe('before_beacon', function(o) {
var html = "", t_name, t_other, others = [];

        if(!o.t_other) o.t_other = "";

        for(var k in o) {
            if(!k.match(/^(t_done|t_other|bw|lat|bw_err|lat_err|u|r2?)$/)) {
                if(k.match(/^t_/)) {
                    o.t_other += "," + k + "|" + o[k];
                }
                else {
                    others.push(k + " = " + o[k]);
                }
            }
        }

        if(o.t_done) { html += "This page took " + o.t_done + " ms to load<br>"; }
        if(o.t_other) {
            t_other = o.t_other.replace(/^,/, '').replace(/\|/g, ' = ').split(',');
            html += "Other timers measured: <br>";
            for(var i=0; i<t_other.length; i++) {
                html += "&nbsp;&nbsp;&nbsp;" + t_other[i] + " ms<br>";
            }
        }
        if(o.bw) { html += "Your bandwidth to this server is " + parseInt(o.bw*8/1024) + "kbps (&#x00b1;" + parseInt(o.bw_err*100/o.bw) + "%)<br>"; }
        if(o.lat) { html += "Your latency to this server is " + parseInt(o.lat) + "&#x00b1;" + o.lat_err + "ms<br>"; }

        var r = document.getElementById('results');
        r.innerHTML = html;

        if(others.length) {
            r.innerHTML += "Other parameters:<br>";

            for(var i=0; i<others.length; i++) {
                var t = document.createTextNode(others[i]);
                r.innerHTML += "&nbsp;&nbsp;&nbsp;";
                r.appendChild(t);
                r.innerHTML += "<br>";

            }
        }
});

当我运行这个 BOOMR.subscribe 函数时没有被执行。我不明白为什么?我已经使用链接http://github.com/lognormal/boomerang/包含了 Boomerang 文件夹

4

1 回答 1

0

您正在使用没有任何插件的回旋镖,因此它无法运行。自述文件在顶部附近有以下文本:

您必须至少包含一个插件(它不必是 rt),否则实际上永远不会调用信标。

https://github.com/lognormal/boomerang/blob/master/README.md

于 2015-04-05T13:39:22.840 回答