我可以选择性刷新JSP页面中的内容吗?

时间:2012-12-26 13:18:40

标签: java html jsp page-refresh partial-page-refresh

似乎很奇怪但仍然:

有什么方法可以让jsp页面的选择部分得到刷新?假设:

<% response.setIntHeader("Refresh",1); // refresh at an interval of 1 second %>

<!-- Html5 snippet that plays a sound that lasts more than a second !-->

<% jsp code %>

现在,我希望当页面刷新时,音频片段从它离开的位置开始。那可能吗 ?剪辑的大小 2.4 MB

1 个答案:

答案 0 :(得分:4)

使用Jquery刷新JSP中的perticular div元素

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/
libs/jquery/1.3.0/jquery.min.js"></script>
<script type="text/javascript">
var auto_refresh = setInterval(
function ()
{
$('#load_tweets').load('record_count.php').fadeIn("slow");
}, 10000); // refresh every 10000 milliseconds
</script>

<body>
  <div id="load_tweets"> </div>
</body>

<强> EDIT1

reload-window.jsp //将此文件放在WEB-INF旁边

<%@page import="java.util.Calendar"%>
<%@page import="java.util.GregorianCalendar"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>

<%! GregorianCalendar newYear = new GregorianCalendar(2013, 0, 1);

    /*
     * 0 : January
     * 1 : 1st January
     * 2013 : year
     */%>
        <div>
        Time : 
        <%= (newYear.getTimeInMillis() - new GregorianCalendar().getTimeInMillis()) / 1000%>
        </div>

<强> main.jsp中

<%-- 
    Document   : nyblast
    Created on : Dec 26, 2012, 10:44:27 AM
    Author     : non-admin
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body bgcolor="#73AF59">

<script type="text/javascript" src="/js/jquery.min.js">

        </script>
<script type="text/javascript">
            var auto_refresh = setInterval(
            function ()
            {
                $('#load_tweets').load('reload-window.jsp').fadeIn("slow");
            }, 5000); // refresh every 10000 milliseconds

          </script>



<table width="100%">
    <tr>
        <td width="40%"></td>
        <td><img src="images/animations/pyear.gif" /></td>
    </tr>
    <tr>
        <td width="40%">
        <center><font face="Chiller" size="+6"> <br />
        Countdown </font></center>
        </td>
        <td>
        <center><font face="Chiller" size="+6"> <br />

        <div id="load_tweets"></div>
        </font></center>
        </td>
    </tr>
    <tr>
        <td colspan="2" style="height: 400px" valign="bottom"><img
            src="images/animations/3D_balloons.gif" /> <em>This poor design
        and animations compiled by Suhail Gupta.</em> <audio
            style="visibility: hidden"> </audio></td>
    </tr>
    <!-- !-->
</table>

</body>

</html>

这里的问题

$('#load_tweets').load('reload-window.jsp').fadeIn("slow");
                }, 5000); // refresh every 5000 milliseconds

加载函数我们需要传递需要刷新的JSP

确保你的js位于正确的位置。