0

I am trying to display the note attribute that I saved into my request.setAttribute("entries", entries), but I can't access this data in my jsp and I can't figure it out. I've tried {note} , but that doesn't work.

This is my controller class:

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


        }   

}

This is my jsp view:

<?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>
Onik
  • 19,396
  • 14
  • 68
  • 91
user3225981
  • 107
  • 7

1 Answers1

0

You already have your List in your request so:

Then you can, (for example) put info a table:

<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>
Community
  • 1
  • 1
Jordi Castilla
  • 26,609
  • 8
  • 70
  • 109
  • yeah this is how i initially did it , but it returns all the notes. i only want 1 note to display. – user3225981 Dec 01 '15 at 02:41
  • mmmm,... just 1 note? which one? first? last? matching any condition? why are you passing a list and not a single entry in the request then? let me know and I will edit my answer accordingly ;) – Jordi Castilla Dec 01 '15 at 09:26