public class test extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
Entry sEntry = new Entry();
sEntry.setEntryID(1);
sEntry.setTitle("sss");
Entry sEntry1 = new Entry();
sEntry1.setEntryID(2);
sEntry1.setTitle("ddd");
List<Entry> entryList = new ArrayList<Entry>();
entryList.add(sEntry);
request.setAttribute("list",entryList);
request.getRequestDispatcher("index.jsp").forward(request, response);
}
}
Entry 对象就是一个结构而已..<c:forEach items="${list}" var="entry">
<tr align="center">
<td>${entry.entryID}</td>
<td>${entry.title}</td>
</tr>
</c:forEach>
在index.jsp上用c:foreach 没办法取到 保存在request里的list这个属性值....
想问下大家这种情况怎么解决
package com.test;
public class Entry {
private int entryID;
private String title;
public int getEntryID() {
return entryID;
}
public void setEntryID(int entryID) {
this.entryID = entryID;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
}Entry.java
public class test extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
Entry sEntry = new Entry();
sEntry.setEntryID(1);
sEntry.setTitle("sss");
Entry sEntry1 = new Entry();
sEntry1.setEntryID(2);
sEntry1.setTitle("ddd");
List<Entry> entryList = new ArrayList<Entry>();
entryList.add(sEntry);
entryList.add(sEntry1);
request.setAttribute("list",entryList);
request.getRequestDispatcher("/index.jsp").forward(request, response);
}
}test.java
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" isELIgnored="false"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<c:forEach items="${list}" var="entry">
<td>${entry.entryid}</td>
<td>${entry.title}</td>
</c:forEach>
<tr align="center">
<td>${entry.entryID}</td>
<td>${entry.title}</td>
</tr></logic:iterate>
换成iterate试一下。
Entry entry = new Entry();
entry.setEntryID(1);
entry.setTitle("sd");
List<Entry> s = new ArrayList<Entry>();
s.add(entry);
request.setAttribute("entry",s);
%>
<c:forEach items="${entry}" var="s">
${s.title}
</c:forEach>直接在页面上存的一个request的就能取出来..orz....应该是servlet的request没传过来