bean.jsp
<%-- JSP学习笔记 --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <jsp:useBean id="person" class="Person" /> <html> <head> <title>jsp测试</title> </head> <body> </body> </html>Person.java
import java.io.Serializable; public class Person implements Serializable{ private String name; private int 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; } }
org.apache.jasper.JasperException: Unable to compile class for JSP: An error occurred at line: 5 in the jsp file: /bean.jsp Person cannot be resolved to a type 2: JSP学习笔记 3: --%> 4: <%@ page contentType="text/html;charset=UTF-8" language="java" %> 5: <jsp:useBean id="person" class="Person" /> 6: <html> 7: <head> 8: <title>jsp测试</title>
观察出错信息:无法编译(*.java --> *.class)
定位到D:Tomcatapache-tomcat-9.0.0.M15workCatalinalocalhost estorgapachejsp
确实也没有生成*.class文件。
经过查资料:JavaBean必须位于某个包内。
package com.xiya; import java.io.Serializable; public class Person implements Serializable{ private String name; private int 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; } }