从servlet跳到jsp页面,并用jstl 进行判断和显示方法
以上是list集合的遍历方式
租房网的detailsServlet
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); String id=request.getParameter("id"); IHouseDAO hd=new HouseDAO(); House house=hd.findById(Integer.parseInt(id)); request.getSession().setAttribute("house", house); request.getRequestDispatcher("page/details.jsp").forward(request, response); out.flush(); out.close(); }
租房网的detail.jsp页面
<c:if test="${sessionScope.house ne null}"> <DIV class=lefter> <H1>${house.getTitle()}</H1> <div class=subinfo><div id="myclock"></div></DIV> <div class=houseinfo> <P>户 型:<SPAN>${house.getTypes().getName()}</SPAN></P> <P>面 积:<SPAN>${house.getFloorage()}m<SUP>2</SUP></SPAN></P> <P>位 置:<SPAN>${house.getStreet().getDistrict().getName()}${house.getStreet().getName()}</SPAN></P> <P>联系方式:<SPAN>${house.getContact()}</SPAN></P> </div> </div> </c:if>
时钟的js实现
<script type="text/javascript"> function clock_24h() { var today = new Date(); //获得当前时间 //获得年、月、日,Date()函数中的月份是从0-11计算 var year = today.getFullYear(); //年 var month = today.getMonth()+1;//月 var date = today.getDate();//日 var hour = today.getHours(); //获得小时、分钟、秒 var minute = today.getMinutes(); var second = today.getSeconds(); /*设置div的内容为当前时间*/ document.getElementById("myclock").innerHTML="<h2>"+year+"-"+month+"-"+date+" "+hour+":"+minute+":"+second+" "+"</h2>"; } /*使用setInterval()每间隔指定毫秒后调用clock_12h()*/ var myTime = setInterval("clock_24h()",1000); </script>