网页不显示最新数据

时间:2016-05-31 13:30:50

标签: jsp spring-mvc

我有一个主页,可以从数据库中获取数据并显示它。

我正在使用spring mvc控制器来更新DB中的数据并返回主页视图。显示主页时,它不显示更新的数据。我需要再次刷新主页以查看最新数据。

我想了解原因并解决。

P.S:我认为这可能与浏览器缓存有关。但删除缓存不起作用,缓存控制元标记也不起作用。

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}&nbsp;
                    </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>

控制器:

@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;
    }

}

流速: 首页 - &GT; deleteInputForm.do-&GT; deleteForm.jsp-&GT; deleteFormDetails.do-&GT;首页

谢谢, Viswanath

0 个答案:

没有答案