Download:
http://www.mediafire.com/file/bdey5hyvga3dg0c/ajax_test.zip
home.jsp
---------------------
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Home</title>
<jsp:include page="header.jsp" />
<script>
$(document).ready(function() {
$("button").click(function() {
$.post("ajaxTest", {
name : "Donald Duck",
city : "Duckburg"
}, function(data, status) {
//alert("Data: " + data + "\nStatus: " + status);
$("#ajaxAdd").append(data);
//console.log("data: ", data);
});
});
});
</script>
</head>
<body>
<h1>User Tbl(user_tbl_view)</h1>
<p id="ajaxAdd">This is a paragraph. </p>
<div class="col-lg-12">
<button>Ajax Test</button>
<div class="table-responsive">
<h1>Contact List (home)</h1>
<h3>
<!-- <a href="newContact">New Contact </a> -->
</h3>
<h3>
<!-- <a href="user_tbl_view">User Tbl </a> -->
</h3>
<table class="table table-bordered table-hover table-striped">
<thead>
<tr>
<th>No</th>
<th>Name</th>
<th>Email</th>
<th>Address</th>
<th>Telephone</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<c:forEach var="contact" items="${listContact}" varStatus="status">
<tr>
<td>${status.index + 1}</td>
<td>${contact.name}</td>
<td>${contact.email}</td>
<td>${contact.address}</td>
<td>${contact.telephone}</td>
<!-- <td><a href="editContact?id=${contact.id}">Edit</a>
<a
href="deleteContact?id=${contact.id}">Delete</a></td>
-->
</tr>
</c:forEach>
</tbody>
</table>
</div>
<!-- /.table-responsive -->
</div>
</body>
</html>
HomeController.java
----------------------------
@RequestMapping(value = "/ajaxTest", method = RequestMethod.POST)
public String ajaxTest(HttpServletRequest request,Model model) {
String name = request.getParameter("name");
String city = request.getParameter("city");
//System.out.println("name="+name + " city="+city);
model.addAttribute("name", name);
model.addAttribute("city", city);
return "ajax_load";
}
ajax_load.jsp
----------------------------
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<body>
ajax_load.jsp city= <c:out value="${city}" /> name= <c:out value="${name}" />
</body>
</html>