主题:[讨论]请教一下如何用javaBean
问一下有哪一位大虾能告诉我怎样用javaBean.
我自己写了一个,但总是运行不出来.
运行环境:JDK1.42 tomcat 5.0.28
运行其他的JSP程序没有问题.
下面的javabean程序编译成了class文件
放在了 C:\Tomcat 5.0\webapps\ROOT\WEB-INF\classes\first 下面
JSP程序放在了 C:\Tomcat 5.0\webapps\ROOT 下面
javabean程序:
package first;
public class FirstBean
{
FirstBean(){}
public void writered(){
System.out.print("*********");
}
}
JSP程序:
<%@ page contentType="text/html;charset=gb2312" language="java" import="java.sql.*,java.io.*"%>
<jsp:useBean id="first" class="first.FirstBean" scope="page"/>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>新建网页 1</title>
</head>
<body>
<% first.writered();%>
this is javabean
</body>
</html>
错误报告:
org.apache.jasper.JasperException: /first.jsp(2,0) The value for the useBean class attribute first.FirstBean is invalid.
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:39)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:409)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:150)
org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1227)
org.apache.jasper.compiler.Node$UseBean.accept(Node.java:1116)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2213)
org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2219)
org.apache.jasper.compiler.Node$Root.accept(Node.java:456)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
org.apache.jasper.compiler.Generator.generate(Generator.java:3272)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:244)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:470)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:451)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:439)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:511)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:295)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
我自己写了一个,但总是运行不出来.
运行环境:JDK1.42 tomcat 5.0.28
运行其他的JSP程序没有问题.
下面的javabean程序编译成了class文件
放在了 C:\Tomcat 5.0\webapps\ROOT\WEB-INF\classes\first 下面
JSP程序放在了 C:\Tomcat 5.0\webapps\ROOT 下面
javabean程序:
package first;
public class FirstBean
{
FirstBean(){}
public void writered(){
System.out.print("*********");
}
}
JSP程序:
<%@ page contentType="text/html;charset=gb2312" language="java" import="java.sql.*,java.io.*"%>
<jsp:useBean id="first" class="first.FirstBean" scope="page"/>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>新建网页 1</title>
</head>
<body>
<% first.writered();%>
this is javabean
</body>
</html>
错误报告:
org.apache.jasper.JasperException: /first.jsp(2,0) The value for the useBean class attribute first.FirstBean is invalid.
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:39)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:409)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:150)
org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1227)
org.apache.jasper.compiler.Node$UseBean.accept(Node.java:1116)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2213)
org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2219)
org.apache.jasper.compiler.Node$Root.accept(Node.java:456)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
org.apache.jasper.compiler.Generator.generate(Generator.java:3272)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:244)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:470)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:451)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:439)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:511)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:295)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)