t1441332354 2018-05-30 08:42 采纳率: 71.8%
浏览 1590
已采纳

如何把一个jsp页面获取的动态时间传送到另一个页面

这是一个jsp页面获取的动态时间

 <%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!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=UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action="111.jsp" method="post" onsubmit="return check(this)">
<script type="text/javascript">
    function display(clock){
        var now = new Date();
        var year = now.getFullYear();
        var month = now.getMonth();
        var date = now.getDate();
        var hour = now.getHours();
        var minu = now.getMinutes();
        var sec = now.getSeconds();
        month = month+1;
        var time = year+"-"+month+"-"+date+" "+hour+":"+minu+":"+sec;
        clock.innerHTML = time;
    }
    window.onload=function(){
        window.setInterval("display(clock)",1000);
    }
</script>
    <table>
        <tr>
            <td>
                <div id="clock"></div>
            </td>
        </tr>
        <tr>
            <td>
                <input type="submit" value="提交">
            </td>
        </tr>
    </table>
</form>
</body>
</html>

如何把这个获取到的时间提交到另一个页面显示出来?获取页面需要怎么改?接收页面应该怎么写?我写的“out.print(request.getParameter("clock"));”表示结果为null。

  • 写回答

17条回答 默认 最新

  • xwh1314 2018-05-31 03:34
    关注
     方法1:
    <input type="submit" value="提交" onclick="submitForm();">
    function submitForm(){
        var time1 = document.getElementById("clock").value;
        document.forms[0].action="111.jsp?time=time1"
        document.forms[0].submit();
    }
    <%  
                String timeContent = request.getParameter("time");  
             %>  
             <br/>  
             <%=timeContent%>
    
    方法3:利用隐藏域传递数据
    可能有问题可以试着改改
    <input type="hidden" name="time1" value="<%=display('this')%>"> 
    <%  
                String timeContent = request.getParameter("time1");  
             %>  
             <br/>  
             <%=timeContent%>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(16条)

报告相同问题?

悬赏问题

  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试