JSTL标签取值问题,配合Struts2,急用,在线等。。。。。。。。。。。
JSTL标签配合Struts2.
这是action代码:
public class FindVetTotal extends ActionSupport{
private List<Vet> list;
public List<Vet> getList() {
return list;
}
public void setList(List<Vet> list) {
this.list = list;
}
public String execute(){
try{
VetDao vd = new VetDaoImpl();
SpecialityDao sd;
List<Vet> temp = vd.findVetTotal();
if(temp != null && temp.size() > 0){
sd = new SpecialityDaoImpl();
for(int i=0; i<temp.size(); i++){
sd.findSpecialityByVetId(temp.get(i));
}
this.list = temp; //赋值给成员变量,temp是我查询回来的数据
return SUCCESS; //然后跳转
}else{
this.addFieldError("error",this.getText("operation.wrong"));
return ERROR;
}
}catch(DataAccessException e){
this.addFieldError("error", this.getText("dbWrong"));
return ERROR;
}catch(ApplicationException e){
this.addFieldError("error", this.getText("systemWrong"));
return ERROR;
}
}
}
然后,我在JSP里取值就出现错误了:
严重: Servlet.service() for servlet jsp threw exception
org.apache.jasper.JasperException: /findVetTotal.jsp(23,4) According to TLD or attribute directive in tag file, attribute items does not accept any expressions
at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
at org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
at org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:148)
at org.apache.jasper.compiler.Validator$ValidateVisitor.checkXmlAttributes(Validator.java:1174)
at org.apache.jasper.compiler.Validator$ValidateVisitor.visit(Validator.java:821)
at org.apache.jasper.compiler.Node$CustomTag.accept(Node.java:1512)
at org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2343)
at org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2393)
at org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2399)
at org.apache.jasper.compiler.Node$Root.accept(Node.java:489)
at org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2343)
...........
这是JSP代码:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page import="com.pet.domain.Vet"%>
<%@taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Test</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
</head>
<body>
<c:forEach items="${list}" var="l"> //这里不是直接取得action的成员变量值吗?
<span>${l.firstName }</span><span>${l.lastName }</span>
<c:forEach items="${l.list}" var="list"> //取出来的对象里还含有一个list,在进行遍历
<span>${list.speName }</span>
</c:forEach>
<br/>
</c:forEach>
</body>
</html>
我使用的是MyEclipse7.5导入的JSTL标签,是1.2版本的。好像出现的是标签库的错误。
请大家帮我看看,刚刚开始学用Struts2,出了这问题,找了好久没找出来。
请大家帮帮忙,谢谢!