如何通过会话获得div的值

时间:2017-10-25 08:07:26

标签: jsp

这是我的 JSP 代码,用于获取两次按钮点击之间的时间差异,并将该时间转换为会话,但我将输出为null。它还会在div中显示名称属性的警告d2。请检查我的代码。

另外,我想问我们可以从div获得价值。  这是 JSP 代码

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
        pageEncoding="ISO-8859-1"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Insert title here</title>
     <link href="assets/css/bootstrap.css" rel="stylesheet" />
        <link href="assets/css/font-awesome.css" rel="stylesheet" />
        <link href="assets/css/custom.css" rel="stylesheet" />
        <script src="bootstrap/js/jquery-3.2.1.js"></script>
         <!-- GOOGLE FONTS-->
       <link href='http://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css' />
       <style type="text/css">
       myButton1:active{
       background-color: red;
       color:red;
       }
       </style>
        <script type="text/javascript">
                var time1 = null;
                var time2 = null;

                //function for getting first time
                function one() {
                    time1 = new Date(); 
                    document.getElementById('first').innerHTML = time1.getHours() + ":" + time1.getMinutes() + ":" + time1.getSeconds();
                }

                //function for getting second time
                function two() {
                    time2 = new Date(); 
                    document.getElementById('second').innerHTML = time2.getHours() + ":" + time2.getMinutes() + ":" + time2.getSeconds();
                    third();
                }

                //function for getting difference
                function third() {
                    var timeDiff = time2 - time1;
                    document.getElementById('next').innerHTML = timeDiff/1000 + " seconds"; 
                }

       function myFunction() {
            var x = document.getElementById('myButton1');
            if (x.style.display === 'none') {
                x.style.display = 'block';
            } else {
                x.style.display = 'none';
            }
            myFunction2();
        }
       function myFunction2() {
            var x = document.getElementById('myButton2');
            if (x.style.display === 'none') {
                x.style.display = 'block';
            } else {
                x.style.display = 'none';
            }
        }
       </script>
    </head>
    <body onLoad="myFunction2()">
    <h2>Click to start a break</h2>
    <input id="myButton1" type="button" value="break start"class="btn btn-success" onclick="myFunction();one();">
    <form action="#">
    <input id="myButton2" type="Submit" value="stop break"class="btn btn-success" onclick="two()">
    </form>
    <div class="totalprice1" id="first"></div>
    <div class="totalprice2" id="second" ></div>
    <div  id="next" name="d2" ></div>
    <%String c=request.getParameter("d2");
//problem is here c prints as null
     session.setAttribute("break",c);
     System.out.println(c);
     out.println(c);%>

    </body>
    </html>

所以请帮助如何在c

中获得价值

0 个答案:

没有答案