Issue
I just started studying JSP, and it goes well if there's a single JSP file.
I create a class file for testing JavaBeans and always get the error "Unable to compile class for JSP" and the web status 500.
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: [9] in the jsp file: [/index.jsp]
person cannot be resolved to a type
---------------------------- The 'person'.class code ------------
import java.lang.*;
public class person {
private String name;
private int age;
private String sex;
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
------------------------- The JSP file -------------------------
<%@ page language="java" contentType="text/html; charset=utf-8" %>
<html>
<head>
<title>Java Bean Actions</title>
</head>
<body><br/>
<jsp:useBean id="person" class="person" scope="page"></jsp:useBean>
<jsp:setProperty name="person" property="*" />
1. Unable to compile the class "person"
Solution
The reason is that your person
class is located at src
folder. Your bean person
must have a package declaration.
More details can be found at Unable to compile this class for JSP.
BTW, it's a bad idea to name your class like person
,it should start with an uppercase,like this Person
Answered By - lucumt