Topic: 简单JavaBean调用老实失败,请兄弟们指教

  Print this page

1.简单JavaBean调用老实失败,请兄弟们指教 Copy to clipboard
Posted by: AaronTong
Posted on: 2007-11-23 10:16

我的代码是《白领就业指南:J2EE开发员成长之路》一书上原版抄过来的,感觉部署都没问题,但是运行的时候老提示错误,我是新手解决不了,已经困惑我好几天了,请指教啊
TaxRate.java如下:
package tax;
public class TaxRate {
String product;
double rate;
public TaxRate(){
this.product = "A001";
this.rate = 5;
}
public void setProduct (String ProductName) {
this.product = ProductName;
}
public String getProduct() {
return (this.product);
}
public void setRate (double rateValue) {
this.rate = rateValue;
}
public double getRate () {
return (this.rate);
}
}
JSP如下:
<HTML>
<BODY>
<%@ page language="java" %>
<jsp:useBean id="taxbean" scope="application" class="tax.TaxRate" />
<% taxbean.setProduct("A002");
taxbean.setRate(17);
%>
产品:<%=taxbean.getProduct() %> <br>
税率:<%=taxbean.getRate() %>
</BODY>
</HTML>
部署如下:TaxRate.java编译后的class文件放在D:\Tomcat5.5\webapps\ROOT\useBean\WEB-INF\classes\tax下。 JSP文件在D:\Tomcat5.5\webapps\ROOT\useBean下。

运行后提示错误:
org.apache.jasper.JasperException: /useBean/UseBean.jsp(4,0) The value for the useBean class attribute tax.TaxRate is invalid.
  org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:512)
  org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
  org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
  org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

root cause

org.apache.jasper.JasperException: /useBean/UseBean.jsp(4,0) The value for the useBean class attribute tax.TaxRate is invalid.
  org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:39)
  org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:405)
  org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:146)
  org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1174)
  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:3320)
  org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:198)
  org.apache.jasper.compiler.Compiler.compile(Compiler.java:295)
  org.apache.jasper.compiler.Compiler.compile(Compiler.java:276)
  org.apache.jasper.compiler.Compiler.compile(Compiler.java:264)
  org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:563)
  org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:305)
  org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
  org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

note The full stack trace of the root cause is available in the Apache Tomcat/5.5.20 logs.
请兄弟们指教啊,在线等

2.Re:简单JavaBean调用老实失败,请兄弟们指教 [Re: AaronTong] Copy to clipboard
Posted by: AaronTong
Posted on: 2007-11-23 10:43

问题好像不在代码里面!!!
我刚刚把JavaBean.class文件部署在D:\Tomcat5.5\webapps\ROOT\WEB-INF\classes\tax下,没有自己建工程文件。JSP代码就放在D:\Tomcat5.5\webapps\ROOT下。输入http://localhost:8080/UseBean.jsp后能正确调用。
再在自己的工程文件中输入http://localhost:8080/useBean/UseBean.jsp后也能正确调用。(声明:我声明都没改动过)以前出现的情况也没了。
我怀疑是我的tomcat不稳定,或者是还要做什么我不知道的神秘配置。(系统配置什么的都照书上的配好了,以前没调JavaBean前都没这种问题,现在不调用JavaBean也没问题,只是在调用JavaBean时才有这种问题)
我的tomcat 5.5.20
JDK 1.5

望知道的指教

3.Re:简单JavaBean调用老实失败,请兄弟们指教 [Re: AaronTong] Copy to clipboard
Posted by: 无行
Posted on: 2007-11-24 10:35

听你的意思好像是发布的时候出现了路径设置问题,你看看在TOMECAT-HOME\conf\server.xml里面有没有配好你的工作目录??没有的话在Host标签里加一行
<Context path="/你的工作路径" reloadable="true" workDir="你的工作目录">

4.Re:简单JavaBean调用老实失败,请兄弟们指教 [Re: 无行] Copy to clipboard
Posted by: AaronTong
Posted on: 2007-11-24 15:21

兄弟,还是没用哦
我都郁闷司了

5.Re:简单JavaBean调用老实失败,请兄弟们指教 [Re: AaronTong] Copy to clipboard
Posted by: AaronTong
Posted on: 2007-12-07 14:48

哎,几天不了来,我终于搞懂该怎么调用JAVABEAN和SERVLET了
那个高兴啊~~


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923