我想,以顯示我保存到我的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}! <a href="Logout">Logout</a></p>
<span>JOT <a href="MyNotes">My Notes</a> | <a href="NewNote.jsp">New</a></span>
<br>
<br>
<br>
<p>${note} </p>
<p>${applicationScope.entries.note},</p>
</body>
</html>
你可以用這個試試,$ {} param.entries或$ {} requestScope.entries呀 –