2016-02-10 29 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

相關問題