servlet端如何获得jsp的客户端时间

来源:百度知道 编辑:UC知道 时间:2024/05/29 04:56:29
具体问题是:
jsp页面有个表单,提交时servlet需要获取表单内容和客户端时间
请问我如何获得时间??

用script获得.
首先在表单里定义一个域用来存放日期信息
<form id="form1" action="<%=request.getContextPath()%>/servlet/xxxxxx" method="post">
<input type="hidden" id="currenttime" name="currenttime" />

</form>
按钮如下:
<input type="button" onclick="submitPage();" />

事件代码如下:
<script language="javascript">
function submitPage()
{
document.getElementById("currenttime").value = new Date();
document.forms["form1"].submit();
}
</script>

注意:这个日期传递到后台的时候是个long字符串,首先要转成long型,然后再new java.util.Date(long型数据);

我原来的做法是吧时间封装在FORM里面
然后再在Servlet里面 获取....

new Date()