Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何刷新JSP的内容?_Javascript_Jquery_Ajax_Jsp_Jakarta Ee - Fatal编程技术网

Javascript 如何刷新JSP的内容?

Javascript 如何刷新JSP的内容?,javascript,jquery,ajax,jsp,jakarta-ee,Javascript,Jquery,Ajax,Jsp,Jakarta Ee,我有一个jsp页面,单击一个按钮,我想从bean中获取值,并根据该数据执行一些操作 此按钮不会发布或获取任何内容,只会进行一些UI级别的更改 条件:页面不能被刷新,只有页面的某一部分被刷新,并且只有当按下该按钮时才会被刷新 我有 <wcbase:useBean id="beanUtil" classname="UtilBean"> <c:set property="studentId" value=&

我有一个jsp页面,单击一个按钮,我想从bean中获取值,并根据该数据执行一些操作

此按钮不会发布或获取任何内容,只会进行一些UI级别的更改

条件:页面不能被刷新,只有页面的某一部分被刷新,并且只有当按下该按钮时才会被刷新

我有

 <wcbase:useBean id="beanUtil" classname="UtilBean">
        <c:set property="studentId" value="${WCParam.studentId}" target="${beanUtil}" />
        </wcbase:useBean>
            <c:set property="classId" value="${class.uniqueID}" target="${beanUtil}" />
            <c:set var="listOfStudents" value="${beanUtil.StudentIdsforTransfer}" />
                                
            <c:if test="${not empty listOfStudents}">
                <script>var listOfStudents= true; </script>
            </c:if>
            <c:if test="${empty listOfStudents}">
                <script>var listOfStudents = false;</script>
                </c:if>
放入jsp

 <div id="studentDiv">

 <wcbase:useBean id="beanUtil" classname="UtilBean">
        <c:set property="studentId" value="${WCParam.studentId}" target="${beanUtil}" />
        </wcbase:useBean>
            <c:set property="classId" value="${class.uniqueID}" target="${beanUtil}" />
            <c:set var="listOfStudents" value="${beanUtil.StudentIdsforTransfer}" />
                                
            <c:if test="${not empty listOfStudents}">
                <script>var listOfStudents= true; </script>
            </c:if>
            <c:if test="${empty listOfStudents}">
                <script>var listOfStudents = false;</script>
                </c:if>
</div>

这段代码刷新了页面,但在主页中再次插入了整个页面,并保持在进程中。

您可以借助以下语句刷新JSP页面

TimeUnit.SECONDS.sleep(5); 
它会在5秒钟后重新加载页面。您可以根据需要进行更改

我在我的代码中使用了上面的一行,如下所示..看一看..它可能会对您有所帮助

  <form action="haryana.jsp" method="get" class="values">
            <table cellspacing="4" cellpadding="4">
                <tr>
                    <td>Select Industry</td>
                    <td><select name="sta" class="dropdown">
                            <option>Industry</option>
                            <option>Cotton</option>
                            <option>Sugar</option>
                            </select></td>
                </tr>
                <tr>
                    <td>Select Category </td>
                    <td><select name="ind" class="dropdown">
                            <option>Category</option>
                            <option>Area</option>
                            <option>Production</option>
                            <option>Yield</option>
                        </select></td>
                </tr>
                <tr class="blank_row">

                </tr>
                <tr>
                    <td><input type="submit" value="Submit" style="margin-top: 10px;" name="bt" class="btn btn-primary btn1"/></td>
                </tr>
            </table>
            <%
                if (request.getParameter("bt") != null) 
                {
                    categoryDataset = new DefaultCategoryDataset();
                    try 
                    {
                        st=request.getParameter("sta").toLowerCase();
                        indus = request.getParameter("ind").toLowerCase();
                        String qry = "select year,"+indus+" from "+st+" where year between '2007-08' and '2013-14'  and state='Haryana'";
                        utility ut = new utility();
                        ResultSet rs = ut.DQL(qry);
                        while (rs.next()) 
                        {
                            a=Float.parseFloat(rs.getString(""+indus));
                            b=Math.round(a);
                            categoryDataset.setValue(b, "" + st, "" + rs.getString("year"));
                            data1.setValue("" + rs.getString("year"), b);
                        }
                        JFreeChart chart1 = ChartFactory.createPieChart(""+indus,   data1, true, true, false);
final ChartRenderingInfo info1 = new ChartRenderingInfo(new StandardEntityCollection());
                        final File file2 = new File("F:/JavaAptech/Netbeans 74 applications/MinorProj/web/" + "har1" + st + indus + ".png");
                        img1 = "har1" + st + indus + ".png";
                        ChartUtilities.saveChartAsPNG(file2, chart1, 450, 300, info1);
                        chart1.setBorderVisible(true);
                    } 
                    catch (Exception e) 
                    {
                       // out.println(e);
                        %>
                        <script>
                            alert("Invalid Input/Data Unavailable");
                        </script>
                        <%
                    }%>
        </form>
    </div>
  <div style="float:left;width:70%;height:380px;">
     <%TimeUnit.SECONDS.sleep(5); %>
     <img style="margin-left: 15px;margin-top:3px;width:450px;height: 350px;"  src=     <%=img1%> USEMAP="#chart1"/>

</div>
    <%
         }
    %>
我的建议是 在需要刷新内容的地方调用ajax。 在test.html中,编写代码从bean中获取值。 示例代码

$.ajax({
  url: "test.html",
  context: document.body
}).done(function() {
  $( this ).addClass( "done" );
});
我提供参考


我在帖子中提到的页面不能刷新编辑不会刷新整个页面。您可以将其放在要刷新的div标记中,它将只刷新该部分而不是整个页面。尝试使用它,你会理解我想说的事实上我理解你的意思,但是除非执行某些操作,否则div也不能刷新。你的div标签是在点击按钮后显示的,还是在页面加载时已经在页面上了?当你不需要加载整个页面时调用ajax你不能像JohnRose说的那样使用JSP这应该通过ajax完成,您必须向服务器发送一个异步请求以获取数据(例如json)并手动修改html。您能告诉我如何在javaScript/jQuery中调用bean的方法吗?
$.ajax({
  url: "test.html",
  context: document.body
}).done(function() {
  $( this ).addClass( "done" );
});