You don't need @page import
. This is only linked into the scriptlet scope, not into taglibs. You don't want to use scriptlets here. The following should work:
<jsp:useBean id="user" class="com.example.Data" scope="session"/>
Further, you should always put classes in a package whenever you'd like to import/reuse it in other classes. Packageless classes are not importable in other classes. Add a package
declaration and put the class in the right location in the folder structure.
package com.example;
public class Data {
// ...
}
When building manually, it should end up in /WEB-INF/classes/com/example/Data.class
. When building using an IDE, like Eclipse, put it in src/com/example/Data.java
and the IDE will worry about compiling and putting it in the right location.
You should also really fix the naming conventions of the variables and getters/setters. Follow the Java Naming Conventions.
Update as per the comments:
thanks... i did it what you said here.. still with the same issue.. now error says Cannot find any information on property 'Data' in a bean of type 'Ont.Data'
First: please, follow the Java Naming Conventions. Package names should not start with uppercase. Further, this error message means that there's no getter for the named property. You should also really follow the Javabean specifications. Property names should start with lowercase, e.g. propertyname
and getter methods should be public
and be named like so getPropertyname()
, a get
, then first letter of propertyname uppercased and the remnant exactly the same as original propertyname. The same applies for setters like so setPropertyname()
.
Here's a rewrite of your Data
class:
package com.example;
public class Data {
private String classname;
private String individualname;
private String link;
public String getClassname() {
return classname;
}
public String getIndividualname() {
return individualname;
}
public String getLink() {
return link;
}
public void setClassname(String classname) {
this.classname = classname;
}
public void setIndividualname(String individualname) {
this.individualname = individualname;
}
public void setLink(String link) {
this.link = link;
}
}
Most IDE's, for example Eclipse, can autogenerate Javabeans in this flavor. Take benefit of it.
See also: