2016-02-10 28 views
1

我有一个从数据库中获取总和的jsp。我想在用户在标题中打开的每个网页上显示此内容。这里总共有8页,从索引页打开的时候开始,让它成为用户打开的任何页面,页眉应该是固定的。我目前的代码如下。在所有的jsps中添加一个jsp作为头文件

的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> 

预期吾道返回值。这里的问题是,当我打开页面(index.jsp)。显示文本标题,并将其重定向到下一页,而不是在标题本身中显示结果。我正在考虑像框架这样的概念,框架中的操作在那里完成,尽管它被重定向到其他页面。

下面是我的CSS头。

.header { 
    position: fixed; 
    top: 0px; 
    left: 0px; 
    width: 100%; 
    padding: 8px; 
    padding-bottom: 5em; 
} 

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

感谢

+0

没明白的问题。但也许OP正在寻找像_apache-tiles_这样的东西。 –

回答

-1

添加这样

<%@ include file="header.jsp" %>

+0

Hi @ ravi这就是我在做什么,这里的区别是我的网页名称是counts.jsp,你给它作为header.jsp – user3872094

+0

它的样本....名称有什么问题,你可以通过任何名称代替header.jsp –

+0

如果你看到我的index.jsp代码(第一个块),这已经存在了。 – user3872094

相关问题