2015-11-30 69 views
0

我想,以顯示我保存到我的request.setAttribute("entries", entries)筆記屬性,但我不能在我的jsp訪問這些數據,我無法弄清楚。我試過{note},但那不起作用。JSP和獲取的屬性數據

這是我的控制器類:

   while(rs.next()) 
       { 
         int id   = rs.getInt("id"); 
         String name  = rs.getString("name"); 
         String note  = rs.getString("note"); 
         String title = rs.getString("title"); 

         Notes entry = new Notes(id, name, note, title); 
         entries.add(entry); 
       } 

       request.setAttribute("entries", entries); 

       request.getRequestDispatcher("/WEB-INF/homework2/MyNotes.jsp").forward(
        request, response); 


      } 
      catch(SQLException e) 
      { 
       throw new ServletException(e); 
      } 
      finally 
      { 
       try 
       { 
        if(c != null) c.close(); 
       } 
       catch(SQLException e) 
       { 
        throw new ServletException(e); 
       } 
      } 


     } 

} 

這是我jsp觀點:

<?xml version="1.0" encoding="ISO-8859-1" ?> 
<%@ 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" %> 
<%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql" %> 

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
    <html xmlns="http://www.w3.org/1999/xhtml"> 
    <head> 
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> 
    <title>MyNotes</title> 
    </head> 
    <body> 

    <p align="right">Hello, ${sessionScope.CurrentUser}!&nbsp;&nbsp;&nbsp;<a href="Logout">Logout</a></p> 
    <span>JOT&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="MyNotes">My Notes</a>&nbsp;|&nbsp;<a href="NewNote.jsp">New</a></span> 
    <br> 
    <br> 
    <br> 


    <p>${note} </p> 
    <p>${applicationScope.entries.note},</p> 

    </body> 
    </html> 
+1

你可以用這個試試,$ {} param.entries或$ {} requestScope.entries呀 –

回答

0

你已經在你的List在你的請求,以便:

然後你就可以,(例如)把信息表:

<c:forEach items="${requestScope.entries}" var="entry"> 
    <tr> 
     <td>ID: <c:out value="${entry.id}"/></td> 
     <td>Name: <c:out value="${entry.name}"/></td> 
     <td>Note: <c:out value="${entry.note}"/></td> 
     <td>Title: <c:out value="${entry.title}"/></td> 
    </tr> 
</c:forEach> 
+0

這是我最初是怎麼做的,但是它會返回所有的音符。我只想要1個音符來顯示。 – user3225981

+0

mmmm,...只是1個音符?哪一個?第一?持續?匹配任何條件?爲什麼你在請求中傳遞一個列表而不是單個條目呢?讓我知道,我會相應地編輯我的答案;) –