jsp頁面
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>useBean 測試頁面</title>
</head>
<body>
<h1>useBean測試頁面</h1>
<jsp:useBean id="person" class="test.Person" scope="page"></jsp:useBean>
<jsp:setProperty property="name" name="person" value="xiaowang"/>
<jsp:setProperty property="age" name="person" value="65" />
<jsp:getProperty property="name" name="person"/><br>
<jsp:getProperty property="age " name="person"/><br>
</body>
</html>
javaBean代碼
package test;
public class Person {
private String name;
private int age;
public Person(){}
public Person(String name,int age){
this.name=name;
this.age=age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
運行後結果:
要麼就是找不到類,要麼就是屬性值找不到。求大神指教
type Exception report
message Cannot find any information on property 'age ' in a bean of type 'test.Person'
description The server encountered an internal error that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: Cannot find any information on property 'age ' in a bean of type 'test.Person'
org.apache.jasper.runtime.JspRuntimeLibrary.getReadMethod(JspRuntimeLibrary.java:825)
org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1144)
org.apache.jasper.compiler.Node$GetProperty.accept(Node.java:1140)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2392)
org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2444)
org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2450)
org.apache.jasper.compiler.Node$Root.accept(Node.java:474)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2392)
org.apache.jasper.compiler.Generator.generate(Generator.java:3581)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:251)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:374)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:354)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:341)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:662)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:364)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.68 logs.
首先你的age後面多了個空格,太粗心了