【问题标题】:add a jsp in all the jsps as header在所有jsps中添加一个jsp作为header
【发布时间】:2016-02-10 13:15:48
【问题描述】:

我有一个从数据库中获取总和的 jsp。我想在用户在标题中打开的每个网页上显示这个。这里总共有8页,从打开索引页开始,不管是用户打开的任何页面,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>

MyServlet

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

请让我知道我该怎么做。我希望结果显示在标题部分本身。

谢谢

【问题讨论】:

  • 不明白这个问题。但也许 OP 正在寻找类似 apache-tiles. 的东西

标签: java html css jsp


【解决方案1】:

像这样添加

&lt;%@ include file="header.jsp" %&gt;

【讨论】:

  • Hi@ravi 这就是我正在做的,这里的区别是我的页面名称是 counts.jsp 而你把它作为 header.jsp
  • 它的示例 .... 名称有什么问题,您可以传递任何名称来代替 header.jsp
  • 如果你看到我的 index.jsp 代码(第一个块),这已经存在了。
  • 制作一个 js 文件并在 js 文件中制作函数以从数据库中获取数据并将该文件包含在每个 jsp 页面中并从 js 文件中调用 jsp 文件中的该函数你懂吗?
猜你喜欢
  • 2013-03-18
  • 2017-05-20
  • 2015-01-21
  • 2015-04-10
  • 1970-01-01
  • 2023-03-18
  • 2010-12-24
  • 1970-01-01
  • 2018-01-29
相关资源
最近更新 更多