主题:使用javabean封装出了问题!求助
初学者刚开始学习使用jsp
这是我写的bean类 userbean.java
package beantest
import java.io.*;
public class userbean
{
private String username;
private String password;
public void setUsername(String username)
{
this.username=username;
}
public void setPassword(String password)
{
this.password=password;
}
public String getUsername()
{
return username;
}
public String getPassword()
{
return password;
}
}
这是测试代码 test.jsp
<html>
<jsp:useBean id="hello" class="beantest.userbean" scope="page" />
<jsp:setProperty name="hello" property="*" />
your username is:<jsp:getProperty name="hello" property="username"/>
<br><br>
your password is:<jsp:getProperty name="hello" property="password"/>
<br><br>
</html>
编译好的类我放到了 Tomcat 4.1\webapps\javabean\WEB-INF\classes\beantest下
出现错误提示如下
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 2 in the jsp file: /test.jsp
Generated servlet error:
[javac] Compiling 1 source file
D:\毕业设计区\Tomcat 4.1\work\Standalone\localhost\javabean\test_jsp.java:42: package beantest does not exist
beantest.userbean hello = null;
^
An error occurred at line: 2 in the jsp file: /test.jsp
Generated servlet error:
D:\毕业设计区\Tomcat 4.1\work\Standalone\localhost\javabean\test_jsp.java:44: package beantest does not exist
hello = (beantest.userbean) pageContext.getAttribute("hello", PageContext.PAGE_SCOPE);
^
An error occurred at line: 2 in the jsp file: /test.jsp
Generated servlet error:
D:\毕业设计区\Tomcat 4.1\work\Standalone\localhost\javabean\test_jsp.java:47: package beantest does not exist
hello = (beantest.userbean) java.beans.Beans.instantiate(this.getClass().getClassLoader(), "beantest.userbean");
^
An error occurred at line: 6 in the jsp file: /test.jsp
Generated servlet error:
D:\毕业设计区\Tomcat 4.1\work\Standalone\localhost\javabean\test_jsp.java:59: package beantest does not exist
out.print(JspRuntimeLibrary.toString((((beantest.userbean)pageContext.findAttribute("hello")).getUsername())));
^
An error occurred at line: 10 in the jsp file: /test.jsp
Generated servlet error:
D:\毕业设计区\Tomcat 4.1\work\Standalone\localhost\javabean\test_jsp.java:63: package beantest does not exist
out.print(JspRuntimeLibrary.toString((((beantest.userbean)pageContext.findAttribute("hello")).getPassword())));
^
5 errors
试了好几个小时了 就是不知道问题出在哪里 请高手帮忙!!不盛感激!!
这是我写的bean类 userbean.java
package beantest
import java.io.*;
public class userbean
{
private String username;
private String password;
public void setUsername(String username)
{
this.username=username;
}
public void setPassword(String password)
{
this.password=password;
}
public String getUsername()
{
return username;
}
public String getPassword()
{
return password;
}
}
这是测试代码 test.jsp
<html>
<jsp:useBean id="hello" class="beantest.userbean" scope="page" />
<jsp:setProperty name="hello" property="*" />
your username is:<jsp:getProperty name="hello" property="username"/>
<br><br>
your password is:<jsp:getProperty name="hello" property="password"/>
<br><br>
</html>
编译好的类我放到了 Tomcat 4.1\webapps\javabean\WEB-INF\classes\beantest下
出现错误提示如下
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 2 in the jsp file: /test.jsp
Generated servlet error:
[javac] Compiling 1 source file
D:\毕业设计区\Tomcat 4.1\work\Standalone\localhost\javabean\test_jsp.java:42: package beantest does not exist
beantest.userbean hello = null;
^
An error occurred at line: 2 in the jsp file: /test.jsp
Generated servlet error:
D:\毕业设计区\Tomcat 4.1\work\Standalone\localhost\javabean\test_jsp.java:44: package beantest does not exist
hello = (beantest.userbean) pageContext.getAttribute("hello", PageContext.PAGE_SCOPE);
^
An error occurred at line: 2 in the jsp file: /test.jsp
Generated servlet error:
D:\毕业设计区\Tomcat 4.1\work\Standalone\localhost\javabean\test_jsp.java:47: package beantest does not exist
hello = (beantest.userbean) java.beans.Beans.instantiate(this.getClass().getClassLoader(), "beantest.userbean");
^
An error occurred at line: 6 in the jsp file: /test.jsp
Generated servlet error:
D:\毕业设计区\Tomcat 4.1\work\Standalone\localhost\javabean\test_jsp.java:59: package beantest does not exist
out.print(JspRuntimeLibrary.toString((((beantest.userbean)pageContext.findAttribute("hello")).getUsername())));
^
An error occurred at line: 10 in the jsp file: /test.jsp
Generated servlet error:
D:\毕业设计区\Tomcat 4.1\work\Standalone\localhost\javabean\test_jsp.java:63: package beantest does not exist
out.print(JspRuntimeLibrary.toString((((beantest.userbean)pageContext.findAttribute("hello")).getPassword())));
^
5 errors
试了好几个小时了 就是不知道问题出在哪里 请高手帮忙!!不盛感激!!