我有一个从数据库中获取总和的 jsp。我想在用户在标题中打开的每个网页上显示此内容。这里一共有8个页面,从index页面打开开始,随便用户打开哪个页面,header都应该是固定的。我当前的代码如下。
index.jsp
<body>
<div class="header"><jsp:include page="counts.jsp" /></div>
Title
</body>
我使用以下文件获取计数。 counts.jsp
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<script type="text/javascript">
function submitForm() {
document.getElementById("form1").submit();
}
window.onload = submitForm;
</script>
</head>
<body>
<form action="GetTheCounts" method="get" id="form1"></form>
</body>
</html>
我的Servlet
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
GetTheCountsDAO getTheCountsDAO = new GetTheCountsDAO();
try {
int excelCount = getTheCountsDAO.getTotalFromExcel();
int DAOCount = getTheCountsDAO.getTotalFromDB();
double getEffeciency = getTheCountsDAO.getEffeciency();
request.setAttribute("DAOCount", DAOCount);
request.setAttribute("excelCount", excelCount);
request.setAttribute("effeciency", getEffeciency);
request.getRequestDispatcher("counts1.jsp").forward(request, response);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
counts1.jsp(实际显示计数)
<body>
<div class="status">
<span class="totalTime">Count is ${DAOCount}/${excelCount}</span> <span
class="efficiency">${effeciency}</span>
</div>
</body>
我的 DAO 正在按预期返回值。这里的问题是,当我打开页面(index.jsp)时。显示文本标题并将其重定向到下一页,而不是在标题本身中显示结果。我在想像框架这样的概念,框架中的操作是在那里完成的,尽管它被重定向到其他页面。
下面是我的标题 CSS。
.header {
position: fixed;
top: 0px;
left: 0px;
width: 100%;
padding: 8px;
padding-bottom: 5em;
}
请让我知道我该怎么做。我希望结果显示在标题部分本身。
谢谢
最佳答案
像这样添加
<%@ include file="header.jsp" %>
关于java - 在所有jsp中添加一个jsp作为header,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35316323/