JSP 2.0自定义标记:无法找到setter方法?

时间:2012-09-23 02:31:28

标签: jsp exception jsp-tags

对“JSP”来说很新鲜;我正在使用带有xampp的Eclipse Juno(Tomcat 7.0.28)。 我创建了以下jsp标记文件:

<%@ tag language="java" pageEncoding="ISO-8859-1" body-content="empty" description="Read Property from the Application's properties file."%>  
<%@ attribute name="Key" required="true" description="Key for searching Properties File."   type="java.lang.String"%>  
<% System.out.println(Key); %>  

在JSP中使用相同的内容时:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib prefix="app" tagdir="/WEB-INF/tags/app" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title><app:random/></title>
</head>
<body>
    <app:getProp Key="APP.TITLE"/>
</body>
</html>

我已将标记文件放在:/ WEB-INF / tags / app中。 但在执行文件时,我得到以下异常:

2012年9月23日上午7:49:19 org.apache.catalina.core.StandardWrapperValve调用 严重:Servlet [jsp]的Servlet.service()在路径[/ MedCamp]的上下文中引发了异常[/index.jsp(line:11,column:1)无法找到属性的Keyter方法:Key]有根本原因 org.apache.jasper.JasperException:/index.jsp(第11行,第1列)无法找到属性的setter方法:Key     在org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:42)     在org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:408)     在org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:149)     at org.apache.jasper.compiler.Generator $ GenerateVisitor.evaluateAttribute(Generator.java:2865)     at org.apache.jasper.compiler.Generator $ GenerateVisitor.generateSetters(Generator.java:3089)     at org.apache.jasper.compiler.Generator $ GenerateVisitor.generateCustomDoTag(Generator.java:2507)     at org.apache.jasper.compiler.Generator $ GenerateVisitor.visit(Generator.java:1748)     在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.Generator.generate(Generator.java:3490)     在org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:250)     在org.apache.jasper.compiler.Compiler.compile(Compiler.java:373)     在org.apache.jasper.compiler.Compiler.compile(Compiler.java:353)     在org.apache.jasper.compiler.Compiler.compile(Compiler.java:340)     at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:646)     在org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357)     在org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)     在org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)     在javax.servlet.http.HttpServlet.service(HttpServlet.java:722)     在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)     在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)     在org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)     在org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)     在org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)     在org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)     at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)     在org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)     在org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)     在org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)     在org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1001)     at org.apache.coyote.AbstractProtocol $ AbstractConnectionHandler.process(AbstractProtocol.java:579)     at org.apache.tomcat.util.net.JIoEndpoint $ SocketProcessor.run(JIoEndpoint.java:310)     at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)     at java.util.concurrent.ThreadPoolExecutor $ Worker.run(Unknown Source)     在java.lang.Thread.run(未知来源)

请让我知道我做错了什么?

1 个答案:

答案 0 :(得分:2)

传递给标记文件的属性名称应以小写字母开头。将您的Key属性重命名为key,您的代码就可以使用。