如題:在做一個servlet的練習的時候用到了jstl標籤的迭代,卻出現了以上的錯誤:
最後發現錯誤在下面的jsp頁面,在貼出來:該引用的也都引用了。
<%@ page language="java" contentType="text/xml; charset=UTF-8" import="java.util.*" pageEncoding="utf-8"%><?xml version="1.0" encoding="UTF-8"?>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<videonews >
<c:forEach items="videos" var="video" >
<news id="${video.id}">
<title>${video.title}</title>
<titllength>${video.timelength}</titllength>
</news>
</c:forEach>
</videonews>
一開始在網上找問題所在:
有人說是bean的屬性名稱錯誤,或者沒有get,set方法,但是我的bean如下:
/**
* @FILE:News.java
* @AUTHOR:Administrator
* @DATE:2013-5-19 下午6:08:00
**/
package com.yehui.service.bean;
/*******************************************
*
* @CLASS:News
* @DESCRIPTION:
* @AUTHOR:Administrator
* @VERSION:v1.0
* @DATE:2013-5-19 下午6:08:00
*******************************************/
public class News {
private Integer id;
private String title;
private Integer timelength;
public News() {
}
public News(Integer id, String title, Integer timelength) {
this.id = id;
this.title = title;
this.timelength = timelength;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public Integer getTimelength() {
return timelength;
}
public void setTimelength(Integer timelength) {
this.timelength = timelength;
}
}
什麼都對,什麼都有,哈哈
最後又錯誤的認爲沒有給工程加jstl jar包,又累死累活的到網上找好jar包,加入到web-inf/lib下,依然還是那個錯誤。都有點絕望了,突然間看到http://201205083157.iteye.com/blog/1536873這篇文章,才意識到了自己犯了一個嚴重的錯誤。哈哈:
<c:forEach items="videos" var="video" >
這句應該寫作
<c:forEach items="${videos}" var="video" >
纔對。也就是那個文章的作者說的,都沒有找到videos這個對象,怎麼能找到它的屬性呢?