Hi, I am trying to run an examples using beans from the book JavaServr Pages
by larne Pekowsky. Could not get it work. I am using Tomcat3.21.
Basically, beanexample1.jsp tries to get properties from Bean1.java. When I
run it I got Error 500:
Internal Servlet Error:
org.apache.jasper.JasperException: Unable to load class
com.awl.jspbook.ch04.Bean1
......
......
Then I did the following:
1. changed <jsp:useBean id="bean1" class="com.awl.jspbook.ch04.Bean1"/> in
the file beanexample1.jsp so it looks like this:
<jsp:useBean id="bean1" class="ch04.Bean1"/>
2. I created subdirectory ch04 under WEB-INF/class and put into it the file
Bean1.java.
3. I also modified the Bean1.java so that the line where you put the
Bean1.java in the package ch04 looks like this: package ch04
However, when I run it I got this error message:
Internal Servlet Error:
org.apache.jasper.JasperException: Unable to compile class for JSP
.....
.....
Root cause:
java.lang.NullPointerException
at
org.apache.jasper.compiler.GetPropertyGenerator.generate(GetPropertyGenerato
r.java:100)
Can anyone tell me what is wrong?
Roland
//This the file beanexample1.jsp
<jsp:useBean id="bean1" class="com.awl.jspbook.ch04.Bean1"/>
<HTML>
<HEAD><TITLE>Beans!</TITLE></HEAD>
<BODY BGCOLOR="#FFFFFF">
<P>Here is some data that came from bean1:</P>
<UL>
<LI>The name of this bean is:
<jsp:getProperty name="bean1" property="name"/>
<LI>The 7th prime number is:
<jsp:getProperty name="bean1" property="seventhPrimeNumber"/>
<LI>The current time is:
<jsp:getProperty name="bean1" property="currentTime"/>
</UL>
<CENTER>
<TABLE BORDER="0">
<TR>
<TD BGCOLOR="<jsp:getProperty name="bean1" property="color"/>">
<P>The information from a bean can be used
anywhere on the page!</P>
</TD>
</TR>
</TABLE>
</BODY>
</HTML>
//This is the file Bean1.java
package com.awl.jspbook.ch04;
import java.text.*;
import java.util.*;
public class Bean1 implements java.io.Serializable {
public String getName() {
return "com.awl.jspbook.ch04";
}
public int getSeventhPrimeNumber() {
return 17;
}
public String getColor() {
return "#772266";
}
public String getCurrentTime() {
SimpleDateFormat sdf = new SimpleDateFormat("hh:mm 'and' s 'seconds'");
return sdf.format(new Date());
}
}
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets