jsp出错:a null object.

dellon_z 2002-05-08 04:27:21
jsp出错信息如下:
type Exception report

message Internal Server Error

description The server encountered an internal error (Internal Server Error) that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: Attempted a bean operation on a null object.


原码:
<jsp:useBean id="myCar" class="com.wrox.cars.CarBean" />
i have a <jsp:getProperty name="mycar" property="make" /> <br />
my car cost $<jsp:getProperty name="mycar" property="price" />

javaBean源码:
package com.wrox.cars;
import java.io.Serializable;
public class CarBean implements Serializable {
public CarBean() {
}
private String make = "ford";
public String getMake() {
return make;
}
public void setMake(String make) {
this.make = make;
}
private double cost = 1000.00;
private double taxRate = 17.5;

public double getPrice() {
double price = (cost + (cost * (taxRate/100)));
return price;
}
private void setPrice(double newPrice) {
}
}
...全文
11 点赞 收藏 6
写回复
6 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
dellon_z 2002-05-08
不好意思,,谢谢你了,呵呵
回复
可乐加水 2002-05-08
你的下面这段代码里问题很多
<jsp:useBean id="myCar" class="com.wrox.cars.CarBean" />
i have a <jsp:getProperty name="mycar" property="make" /> <br />
my car cost $<jsp:getProperty name="mycar" property="price" />
myCar的大小写应该写对的,不然是找不到的
id="myCar" 与name="mycar" 应该是一样的
所以name="myCar" 才对
回复
可乐加水 2002-05-08
我给改成这样了
import java.io.Serializable;
public class CarBean implements Serializable {
public CarBean() {
}
String make = "ford";
double price=0;
public String getMake() {
return make;
}
public void setMake(String make) {
this.make = make;
}
private double cost = 1000.00;
private double taxRate = 17.5;

public double getPrice() {
price = (cost + (cost * (taxRate/100)));
return price;
}
private void setPrice(double newPrice) {
this.price = newPrice;
}
}

jsp文件
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<META http-equiv="Content-Type" content="text/html; charset=GB2312">
<META name="GENERATOR" content="IBM WebSphere Studio">
<TITLE>test.jsp</TITLE>
</HEAD>
<%@ page language="java"%>
<%@ page import="CarBean"%>

<BODY>
<jsp:useBean id="myCar" class="CarBean"/>
i have a <jsp:getProperty name="myCar" property="make"/> <br/>
my car cost $<jsp:getProperty name="myCar" property="price"/>

<%
int i=1;
if( i >0){
out.print("i>0");
}
if( i< 0){
out.print("i<0");
}
out.println(myCar.getPrice());
out.println(myCar.getMake());
%>
</BODY>
</HTML>
调试通过,运行结果如下:
i have a ford
my car cost $1175.0 i>01175.0 ford
,你也试一下吧
回复
dellon_z 2002-05-08
realyfly(含泪海)
改过了,重起了,还是那个错误,怎么办?


description The server encountered an internal error (Internal Server Error) that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: Attempted a bean operation on a null object.
at org.apache.jasper.runtime.JspRuntimeLibrary.handleGetProperty(JspRuntimeLibrary.java:510)
at org.apache.jsp.carPage2$jsp._jspService(carPage2$jsp.java:87)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:202)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:382)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:474)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:190)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:246)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2343)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:170)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:468)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:1012)
at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1107)
at java.lang.Thread.run(Thread.java:536)

回复
scarab 2002-05-08
很可能是BEAN的路径不对,没有找到该BEAN
回复
可乐加水 2002-05-08
<jsp:getProperty name="mycar" property="price" />
这一句里面指出了bean中有一个price,但是你的
bean里(不是函数里)没有声明它,在

private String make = "ford";下面加一句
double price=0;
并且把
public double getPrice() {
double price = (cost + (cost * (taxRate/100)));
return price;
}
改成
public double getPrice() {
price = (cost + (cost * (taxRate/100)));
return price;
}

回复
发动态
发帖子
Web 开发
创建于2007-09-28

7.9w+

社区成员

Java Web 开发
申请成为版主
社区公告
暂无公告