Java bean運行問題,請幫忙!
本文导语: Tomcat 4.1 JDK 1.3.02_2 Bean Code package testbeans; import java.util.*; public class bean1 { int answer; boolean success; String hint; int numGuesses; public bean1() { reset(); } public void setGuess(String guess) { n...
Bean Code
package testbeans;
import java.util.*;
public class bean1 {
int answer;
boolean success;
String hint;
int numGuesses;
public bean1() {
reset();
}
public void setGuess(String guess) {
numGuesses++;
int g;
try {
g = Integer.parseInt(guess);
}
catch (NumberFormatException e) {
g = -1;
}
if (g == answer) {
success = true;
}
else if (g == -1) {
hint = "a number next time";
}
else if (g answer) {
hint = "lower";
}
}
public boolean getSuccess() {
return success;
}
public String getHint() {
return "" + hint;
}
public int getNumGuesses() {
return numGuesses;
}
public void reset() {
answer = Math.abs(new Random().nextInt() % 100) + 1;
success = false;
numGuesses = 0;
}
}
JSP Code
-------------------------
Number Guess
Congratulations! You got it.
And after just tries.
Care to try again?
Welcome to the Number Guess game.
I'm thinking of a number between 1 and 100.
What's your guess?
Good guess, but nope. Try .
You have made guesses.
I'm thinking of a number between 1 and 100.
What's your guess?
-------
編譯後的class 文件放在了
C:TomcatwebappsexamplesWEB-INFclasses
和C:TomcatwebappsexamplesWEB-INFclassesnum
JSP放
C:Tomcatwebappsexamplesjspnum
重啓Tomcat
瀏覽此JSP出現錯誤
org.apache.jasper.JasperException: Unable to compile class for JSP..worklocalhostexamples_0002fjsp_0002fnum_0002fbean_00031_0002ejspbean1_jsp_0.java:3: import 中未找到类 testbeans.bean1。
import testbeans.bean1;
^
1 个错误
請高手指點了
|
另外,如果你已用
生成了bean的实例,而且又不需要使用bean1 mybean1=new bean1()这样的定义方式,那么
就是多余的
|
|