I have a home page which fetches data from DB and displays it.
I am using a spring mvc controller to update data in DB and return home page view. When the home page is displayed it doesn't show the updated data. I need to refresh home page once again to see latest data.
I am trying to understand the reason and fix.
P.S: I thought it might be something to do with browser cache. But deleting cache doesn't work and also cache control meta tags doesn't work.
Home Page.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="pragma" content="no-cache" />
<title>Home</title>
</head>
<body>
<div id="header">
<%@ include file="headerinclude.jsp"%>
<table>
<tr>
<td><a href="<c:url value="./newStudentPage.do"/>">New
Student</a></td>
<td><a href="<c:url value="./updateInputForm.do"/>">Update
Student</a></td>
<td><a href="<c:url value="./deleteInputForm.do"/>">Delete
Student</a></td>
</tr>
</table>
</div>
<h3>
<c:out value="List of active Students" />
</h3>
<div id="body">
<table id="student-table" border="1" cellpadding="1" cellspacing="1">
<th>FirstName</th>
<th>LAstName</th>
<th>Gender</th>
<th>DOB</th>
<th>Email</th>
<th>MobilNumber</th>
<th>Address</th>
<th>Courses</th>
<c:forEach var="student" items="${studentList}">
<tr>
<td>${student.firstName}</td>
<td>${student.lastName}</td>
<td>${student.gender}</td>
<td>${student.DOB}</td>
<td>${student.email}</td>
<td>${student.mobileNumber}</td>
<td>${student.address}</td>
<td><c:forEach var="course" items="${student.courses}">
${course}
</c:forEach></td>
</tr>
</c:forEach>
</table>
</div>
<div id="footer">
<%@ include file="footerinclude.jsp"%>
</div>
</body>
</html>
deleteForm.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="s"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Update Student Page Request</title>
<link rel="stylesheet" href="./css/global.css" />
</head>
<body>
<div id="header">
<%@ include file="headerinclude.jsp"%>
</div>
<div id="body">
<h3>
<c:out value="Enter User Name Details to delete: " />
</h3>
<s:form method="GET" commandName="updateInputBean"
action="./deleteFormDetails.do">
<s:errors path="*" cssClass="errorblock" element="div" />
<table>
<tr>
<td><s:label path="firstName">First Name</s:label></td>
<td><s:input path="firstName" /></td>
<td><s:errors path="firstName" cssClass="error" /></td>
</tr>
<tr>
<td><s:label path="lastName">Last Name</s:label></td>
<td><s:input path="lastName" /></td>
<td><s:errors path="lastName" cssClass="error" /></td>
</tr>
</table>
<input type="submit" value="delete" />
</s:form>
</div>
<div id="messageDisplay">${ErrorMessage}</div>
<div id="footer">
<%@ include file="footerinclude.jsp"%>
</div>
</body>
</html>
Controller:
@RequestMapping(value = "/deleteInputForm.do", method = RequestMethod.GET)
public ModelAndView deleteInputForm() {
ModelAndView mav = new ModelAndView("deleteFormPage",
"updateInputBean", new UpdateInputBean());
return mav;
}
@RequestMapping(value = "/deleteFormDetails.do", method = RequestMethod.GET)
public ModelAndView deleteFormDetails(
@Valid @ModelAttribute UpdateInputBean updateInputBean,
BindingResult bindingResult, final HttpServletResponse res) {
if (bindingResult.hasErrors()) {
return new ModelAndView("deleteFormPage");
}
boolean deletedRecord = studentDao.deteteStudentByName(
updateInputBean.getFirstName(), updateInputBean.getLastName());
if (deletedRecord) {
res.setHeader("Cache-Control", "no-cache");
return new ModelAndView("home");
} else {
ModelAndView mav = new ModelAndView("deleteFormPage");
mav.addObject("ErrorMessage", "No records Found");
return mav;
}
}
Flow: HomePage->deleteInputForm.do->deleteForm.jsp->deleteFormDetails.do->HomePage
Thanks, Viswanath