[英]How to refresh the content of a JSP?
我有一個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>
我需要將整個部分稱為按鈕單擊
怎么做?
所有幫助將不勝感激。
注意:我試圖將這段代碼放在div中,然后嘗試在單擊按鈕時刷新該div,但是它沒有用。
就像是 :
放入js
$('#studentDiv').load(document.URL + '#studentDiv');
放入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" );
});
我給參考
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.