首页上一页 1 下一页尾页 1 条记录 1/1页
使用Jsp:useBean出现的问题
发表在JavaWeb图书答疑
2011-11-28
是否精华
是
否
版块置顶:
是
否
在学习Java Web 的24堂调查中, 第七堂课 7.2JavaBean 中JSP 中的应用.
先创建类:Bean;
package com.bean;
public class Bean {
private String name;
public BeanFirst(){
}
public String getName(){
return name+"的JavaBean程序";
}
public void setName(String name){
this.name=name;
}
}
编译生成Bean.class (我是用javac Bean.java 生成的, 请问如何用eclipse 生成.class文件?)
com.bean包在index.jsp的当前目录下Dynamic Web\WebRoot引入.
在创建index.jsp 文件:
<%@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030"%>
<%@ page import="com.bean.Bean" %><%--这句有无都出错--%>
<jsp:useBean id="bean" class="com.bean.Bean"></jsp:useBean>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030">
<title>Bean 第一个例子</title>
</head>
<body>
<%bean.setName("Tom"); %>
<h1 align="center"><%=bean.getName()%></h1> <!--这里可以正确识别bean的方法,说明类的引用应该没有问题-->
</body>
编译后出错如下:
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: /index01.jsp(4,0) The value for the useBean class attribute com.bean.BeanFirst is invalid.
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:148)
org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1233)
org.apache.jasper.compiler.Node$UseBean.accept(Node.java:1178)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2361)
org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2411)
org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2417)
org.apache.jasper.compiler.Node$Root.accept(Node.java:495)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2361)
org.apache.jasper.compiler.Generator.generate(Generator.java:3459)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:231)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:354)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:334)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:321)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:592)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:328)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.33 logs.
试验了好多方法, 都是上面的一个提示,
比如在WEB-INF(包括tomcat里面的WEB-INF)下加入Classes\com\bean\Bean.class
请问问题出错在哪里,多谢!
先创建类:Bean;
package com.bean;
public class Bean {
private String name;
public BeanFirst(){
}
public String getName(){
return name+"的JavaBean程序";
}
public void setName(String name){
this.name=name;
}
}
编译生成Bean.class (我是用javac Bean.java 生成的, 请问如何用eclipse 生成.class文件?)
com.bean包在index.jsp的当前目录下Dynamic Web\WebRoot引入.
在创建index.jsp 文件:
<%@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030"%>
<%@ page import="com.bean.Bean" %><%--这句有无都出错--%>
<jsp:useBean id="bean" class="com.bean.Bean"></jsp:useBean>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030">
<title>Bean 第一个例子</title>
</head>
<body>
<%bean.setName("Tom"); %>
<h1 align="center"><%=bean.getName()%></h1> <!--这里可以正确识别bean的方法,说明类的引用应该没有问题-->
</body>
编译后出错如下:
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: /index01.jsp(4,0) The value for the useBean class attribute com.bean.BeanFirst is invalid.
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:148)
org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1233)
org.apache.jasper.compiler.Node$UseBean.accept(Node.java:1178)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2361)
org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2411)
org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2417)
org.apache.jasper.compiler.Node$Root.accept(Node.java:495)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2361)
org.apache.jasper.compiler.Generator.generate(Generator.java:3459)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:231)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:354)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:334)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:321)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:592)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:328)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.33 logs.
试验了好多方法, 都是上面的一个提示,
比如在WEB-INF(包括tomcat里面的WEB-INF)下加入Classes\com\bean\Bean.class
请问问题出错在哪里,多谢!