gpt4 book ai didi

java - 如何将ajax中的值设置到jsp中的表中

转载 作者:太空宇宙 更新时间:2023-11-04 15:23:55 24 4
gpt4 key购买 nike

我有一个带有表的jsp,其中有两列,分别称为status 和numRecords。我通过 ajax 获得新的状态和 numrecords 值。我想要的是将表的 status 和 numrecords 替换为 ajax 上新检索到的值。我已经尝试过这样,这是我的jsp:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>

<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>File Upload</title>
<script type="text/javascript" src="js/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="css/style1.css" />
<link rel="stylesheet" type="text/css" href="css/button.css" />
<link href="css/common-style.css" rel="stylesheet" type="text/css" />
<style>
a{
color:white;
text-decoration:none;
}
</style>
<script type="text/javascript">
var id;
function refreshRecord(value)
{
id = value;
alert(id);
}

$(document).ready(function(){
$("#refresh").click(function(){
var fileId=id;
alert("ajax id is "+fileId);
$.ajax({
type:'post',
url:'checkStatusAndNumRecs',
data:{fileId:fileId},
success:function(data)
{
var obj=data.split(':');
alert("status is :"+obj[0]);
$("#stat").html(obj[0]);
$("#recs").html(obj[1]);
},
error:function(data)
{
$("#div1").html("It was a failure !!!");
}
});
});
});
</script>
</head>
<body>
<%@include file="index1.html" %>
<div class="box2">
<div class="box3">
<s:property value="userId"/>
</div>
<center><h2>FILE STATUS</h2></center>
<center>

<form action="Upload" method="post" enctype="multipart/form-data">
<label for="myFile" class="text">Upload your file:</label>
<input type="hidden" name="upload" value="upload"/>
<input type="file" name="myFile" size="40" class="file"/>
<input type="submit" value="Upload" class="button"/>
<input type="submit" value="Refresh" class="button"/>
</form>
</center>

<center>
<table border="1" class="displaytab" id="rtable">
<s:if test="%{user.roles == 'admin'}">
<tr> <td colspan="10" style="background:#7395B8;color:white;font-size:18px;font-weight:bold;"><center>Admin</center></td></tr>
</s:if>
<tr>
<th>FileId</th><th>File Name</th><th>Upload Date</th><th>#Records</th><th>Status</th><th>Estimated Time</th><th>Processed Records</th><th>Generate Report</th><th></th><s:if test="%{user.roles == 'admin'}"><th>Controls</th></s:if>
</tr>

<s:iterator value="uploadList" var="m">
<tr>
<td><s:property value="%{#m.fileId}" /></td>
<td><s:property value="%{#m.fileName}" /></td>
<td><s:property value="%{#m.uploadDate}" /></td>
<td id="recs"><s:property value="%{#m.numRecords}" /></td>
<td id="stat"><s:property value="%{#m.status}" /></td>
<td>tbd</td>

<td><s:property value="%{#m.numRecords}" /></td>
<td><a href=""><img src="images/generate.png" title="Generate Report"></a></td>
<td><a href=""><img src="images/refresh.png" title="Refresh" id="refresh" onclick="refreshRecord(<s:property value="%{#m.fileId}" />);"></a></td>
<s:if test="%{user.roles == 'admin'}">
<td><a href=""><img src="images/details.png"></a>
<a href=""><img src="images/plus.png" title="Add Instance"></a>
<a href=""><img src="images/minus.png" title="Remove Instance"></a>
<a href=""><img src="images/download.png" title="Download"></a>
<a href=""><img src="images/reconnect.png" title="Reconnect"></a></td>

</s:if>
</tr>
</s:iterator>
</table>
</center>

<br>
<br>
<br>
<br>
<center>
<s:if test="%{user.roles == 'admin'}">

<!-- <select name="user names">
<s:iterator value="userNamesList">
<option value="emailColumn" > <s:property/>
</option>
</s:iterator>
</select> -->

<table border="1" class="displaytab" id="usertab">
<s:if test="%{uploadListMap.size() != 0}">
<tr> <td colspan="10" style="background:#7395B8;color:white;font-size:18px;font-weight:bold;">User Job Details</center></td></tr>
<tr>
<th>FileId</th><th>File Name</th><th>Upload Date</th><th>#Records</th><th>Status</th><th>Estimated Time</th><th>Processed Records</th><th>Generate Report</th><th></th><s:if test="%{user.roles == 'admin'}"><th>Controls</th></s:if>
</tr>
<s:iterator value="%{uploadListMap}">
<tr> <td colspan="10" style="background:#7395B8;color:white;font-size:18px;font-weight:bold;"><center><s:property value="key"/></center></td>
<s:iterator value="value" var="u">
<tr>
<td><s:property value="%{#u.fileId}" /></td>
<td><s:property value="%{#u.fileName}" /></td>
<td><s:property value="%{#u.uploadDate}" /></td>
<td><s:property value="%{#u.numRecords}" /></td>
<td><s:property value="%{#u.status}" /></td>
<td>tbd</td>
<td><s:property value="%{#m.numRecords}" /></td>
<td><a href=""><img src="images/generate.png" title="Generate Report"></a></td>
<td><a href=""><img src="images/refresh.png" title="Refresh" id="refresh" onclick="refreshRecord(<s:property value="%{#u.fileId}" />);"></a></td>
<td><a href=""><img src="images/details.png"></a>
<a href=""><img src="images/plus.png" title="Add Instance"></a>
<a href=""><img src="images/minus.png" title="Remove Instance"></a>
<a href=""><img src="images/download.png" title="Download"></a>
<a href=""><img src="images/reconnect.png" title="Reconnect"></a></td>
</tr>
</s:iterator>
</tr>
</s:iterator>
</s:if>
</table>
</s:if>
</center>
</div>
</body>
</html>

请帮助我,提前致谢。

最佳答案

如果您的操作返回类似于 {"status":"success","re​​cords":"123"} 的 JSON 对象,则设置您可以使用的值

success:function(data) {
alert(JSON.stringify(data));
$("#stat").val(data.status);
$("#recs").val(data.records);
}

关于java - 如何将ajax中的值设置到jsp中的表中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20068500/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com