//javabean如下:package bean;
public class sampleBean
{
private String sample = "Start value";
public String getSample() {
return sample;
}
public void setSample(String newValue) {
if(newValue != null) {
sample = newValue;
}
}
}把以上程序编译之后形成一个class文件,然后得复制到Tomcat 5.5\webapps\ROOT\WEB-INF\classes\bean下//再编一个sample1.jsp文件:<jsp:useBean   id="test"   class="bean.sampleBean"/>
<%=test.getSample()%>然后通过以下地址进行访问http://localhost:8080/myjsp/sample1.jsp
显示正常,页面输出为:Start value//若再编一个sample2.jsp文件对javabean进行调用: <%@ page contentType="text/html;charset=GBK"%>
<html>
<head>
<title>Servlet使用JSP</title>
</head>
<jsp:useBean id="myBean" 
scope="application" class="bean.sampleBean"/>
<body bgcolor="gray">
<h2>JSP使用JavaBean的例子:</h2>
<hr>
调用jsp:setProperty之前的值:
<jsp:getProperty name="myBean" property="sample"/>
<p>
<jsp:setProperty name="myBean" 
property="sample" value="hhhhhhhhhhhhh"/>
调用jsp:setProperty之后的值:
<jsp:getProperty name="myBean1" property="sample"/>
</body>
</html>通过http://localhost:8080/myjsp/sample2.jsp进行访问时却总是发生错误,检查程序,找不出什么问题的,错误提示如下:
HTTP Status 500 - --------------------------------------------------------------------------------type Exception reportmessage description The server encountered an internal error () that prevented it from fulfilling this request.exception org.apache.jasper.JasperException: Attempted a bean operation on a null object.
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375)
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: Attempted a bean operation on a null object.
org.apache.jasper.runtime.JspRuntimeLibrary.handleGetProperty(JspRuntimeLibrary.java:601)
org.apache.jsp.myjsp.sample1_jsp._jspService(org.apache.jsp.myjsp.sample1_jsp:68)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
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.15 logs.
--------------------------------------------------------------------------------Apache Tomcat/5.5.15
实在搞不清楚是什么问题,头都大了,希望知道的朋友帮个忙啊,
叩地为谢