SetProperty:缺少必需的属性属性

时间:2011-06-22 17:32:15

标签: java jsp jstl javabeans

好的,首先是一些代码。这是我的displayCollection.tag的内容:

<%@ tag body-content="scriptless" import="com.serco.inquire.*" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ attribute name="mgr" required="true" %>
<jsp:useBean id="irc" scope="session" class="com.serco.inquire.irCollection">
<jsp:setProperty name="mgrid" value="${mgr}" />
</jsp:useBean>
${irc.mgrid}

这是我从(myq.jsp)调用它的JSP:

<%@page language="java" import="java.util.*,com.serco.inquire.*" %>
<%@ taglib prefix="inq" tagdir="/WEB-INF/tags" %>
<inq:displayCollection mgr="Chris Novish" />

这是irCollection的java类(在标记文件中使用):

package com.serco.inquire;
import java.sql.*;
import java.util.*;
public class irCollection {
public String mgrid;
public irCollection() {
super();
}
public void setMgrid(String datum) {
this.mgrid = datum;
}
public String getMgrid() {
return this.mgrid;
}
}

最后,这是我尝试运行myq.jsp时出现的错误:

  

org.apache.jasper.JasperException:   /WEB-INF/tags/displayCollection.tag(7,2)   SetProperty:强制属性   财产缺失   org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:41)   org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)   org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:198)   org.apache.jasper.compiler.JspUtil.checkAttributes(JspUtil.java:174)   org.apache.jasper.compiler.Validator $ ValidateVisitor.visit(Validator.java:595)   org.apache.jasper.compiler.Node $ SetProperty.accept(Node.java:1150)   org.apache.jasper.compiler.Node $ Nodes.visit(Node.java:2376)   org.apache.jasper.compiler.Node $ Visitor.visitBody(Node.java:2428)   org.apache.jasper.compiler.Validator $ ValidateVisitor.visit(Validator.java:647)   org.apache.jasper.compiler.Node $ UseBean.accept(Node.java:1182)   org.apache.jasper.compiler.Node $ Nodes.visit(Node.java:2376)   org.apache.jasper.compiler.Node $ Visitor.visitBody(Node.java:2428)   org.apache.jasper.compiler.Node $ Visitor.visit(Node.java:2434)   org.apache.jasper.compiler.Node $ Root.accept(Node.java:475)   org.apache.jasper.compiler.Node $ Nodes.visit(Node.java:2376)   org.apache.jasper.compiler.Validator.validateExDirectives(Validator.java:1789)   org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:216)   org.apache.jasper.compiler.Compiler.compile(Compiler.java:372)   org.apache.jasper.compiler.Compiler.compile(Compiler.java:352)   org.apache.jasper.compiler.Compiler.compile(Compiler.java:339)   org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:594)   org.apache.jasper.servlet.JspServletWrapper.loadTagFile(JspServletWrapper.java:231)   org.apache.jasper.compiler.TagFileProcessor.loadTagFile(TagFileProcessor.java:577)   org.apache.jasper.compiler.TagFileProcessor.access $ 000(TagFileProcessor.java:48)   org.apache.jasper.compiler.TagFileProcessor $ TagFileLoaderVisitor.visit(TagFileProcessor.java:642)   org.apache.jasper.compiler.Node $ CustomTag.accept(Node.java:1539)   org.apache.jasper.compiler.Node $ Nodes.visit(Node.java:2376)   org.apache.jasper.compiler.Node $ Visitor.visitBody(Node.java:2428)   org.apache.jasper.compiler.Node $ Visitor.visit(Node.java:2434)   org.apache.jasper.compiler.Node $ Root.accept(Node.java:475)   org.apache.jasper.compiler.Node $ Nodes.visit(Node.java:2376)   org.apache.jasper.compiler.TagFileProcessor.loadTagFiles(TagFileProcessor.java:660)   org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:228)   org.apache.jasper.compiler.Compiler.compile(Compiler.java:372)   org.apache.jasper.compiler.Compiler.compile(Compiler.java:352)   org.apache.jasper.compiler.Compiler.compile(Compiler.java:339)   org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:594)   org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:344)   org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:391)   org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)   javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

据我所知,当调用displayCollection.tag时,属性mgr在myq.jsp中设置,而displayCOllection.tag的唯一属性(必需)是mgr。所以......我误解了什么?

1 个答案:

答案 0 :(得分:2)

仔细查看jsp:setProperty标记上的Sun documentationname属性实际上是id中声明的bean的jsp:useBean属性 - 所以它应该是“irc”。 property上需要setProperty属性,并且是您尝试设置的实际属性。