Java 无法使用Json更新jsp上的表
我正在尝试使用Json从数据库中获取数据,但没有收到错误。单击“显示表格”按钮后,仅显示警报,不显示表格: MyJsp.jspJava 无法使用Json更新jsp上的表,java,javascript,jquery,json,Java,Javascript,Jquery,Json,我正在尝试使用Json从数据库中获取数据,但没有收到错误。单击“显示表格”按钮后,仅显示警报,不显示表格: MyJsp.jsp <script src="jquery.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("#emptable").hide(); $("#showTable").click(func
<script src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#emptable").hide();
$("#showTable").click(function(event){
$.get('EmpServlet',function(responseJson){
if(responseJson!=null){
$("#emptable").find("tr:gt(0)").remove();
var table1= $("#countrytable");
$.each(responseJson,function(key,value){
var rowNew = $("<tr><td></td><td></td><td></td></tr>");
rowNew.children().eq(0).text(value['eid']);
rowNew.children().eq(1).text(value['ename']);
rowNew.children().eq(2).text(value['esal']);
rowNew.appendTo(table1);
});
}
});
$("#tablediv").show();
alert('hhh');
});
});
</script>
<body class="container">
<h1>AJAX Retrieve Data from Database in Servlet and JSP using JSONArray</h1>
<input type="button" value="Show Table" id="showTable"/>
<div id="tablediv">
<table cellspacing="0" id="emptable">
<tr>
<th scope="col">ID</th>
<th scope="col">Name</th>
<th scope="col">Salary</th>
</tr>
</table>
</div>
</body>
及
此“eid”是否与我声明的pojo类员工相同:
String eid;
String ename;
String esal;
public Employee(String eid, String ename, String esal) {
super();
this.eid = eid;
this.ename = ename;
this.esal = esal;
}
public String getEid() {
return eid;
}
public String getEname() {
return ename;
}
public String getEsal() {
return esal;
}
看看这个:
$.get('EmpServlet',function(responseJson){
$.each(responseJson,function(key,value){
...
});
});
您总是得到一个JSON对象作为响应。这意味着,每个
周期只发生一次(如果有的话)。在中,value
参数将是实际数组
我还没有测试过,所以可能我错了
rowNew.children().eq(0).text(value['eid']);
rowNew.children().eq(1).text(value['ename']);
rowNew.children().eq(2).text(value['esal']);
String eid;
String ename;
String esal;
public Employee(String eid, String ename, String esal) {
super();
this.eid = eid;
this.ename = ename;
this.esal = esal;
}
public String getEid() {
return eid;
}
public String getEname() {
return ename;
}
public String getEsal() {
return esal;
}
$.get('EmpServlet',function(responseJson){
$.each(responseJson,function(key,value){
...
});
});