我在JSP里面想要调用JAVABEAN里面的函数,可是出现了问题
JSP里面的代码如下:
<%chap4.PasswordBean.createPassword();%>
JAVABEAN里面的代码如下:
public void createPassword(){
double d = Math.random();
int n =1;
for(int i=0;i<numDigit;i++){
n = n*10;
password = (long)(d*n) + 1;
}
错误提示如下:
\chap4_005f2_jsp.java:77: non-static method createPassword() cannot be referenced from a static context
请问是什么问题又该如何更正呢?
JSP里面的代码如下:
<%chap4.PasswordBean.createPassword();%>
JAVABEAN里面的代码如下:
public void createPassword(){
double d = Math.random();
int n =1;
for(int i=0;i<numDigit;i++){
n = n*10;
password = (long)(d*n) + 1;
}
错误提示如下:
\chap4_005f2_jsp.java:77: non-static method createPassword() cannot be referenced from a static context
请问是什么问题又该如何更正呢?
public class PasswordBean implements Serializable {
private int numDigit;
private long password;
public PasswordBean() {
numDigit = 6;
password = 123456;
}
public void setNumDigit(int n){
if(n<6){
numDigit = n;
}
else{
numDigit = 6;
}
}
public void createPassword(){
double d = Math.random();
int n =1;
for(int i=0;i<numDigit;i++){
n = n*10;
password = (long)(d*n) + 1;
}
}
public int getNumDigit(){
return numDigit;
}
public long getPassword(){
return password;
}
}