You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Roland Dong <RB...@wiu.edu> on 2001/03/06 09:20:36 UTC

RE: Can you help with JSP example?

Thanks, but I tried all the set-up possibilities and still can't make it
work. I suspect there might be something wrong with either beanexample1.jsp
or Bean1.java.

I am attaching the two files and see if someone is interested in trying it
out.


Dude - be sure you are set-up right.....
1) package declaration in the Java source code: com.awl.jspbook.ch04
2) generate or place the CLASS file properly :

tomcat\webapps\examples\jspbook\ch04\WEB-INF\classes\com\awl\jspbook\ch04\be
anWHATEVER.class
or if it is in a JAR file:

tomcat\webapps\examples\jspbook\ch04\WEB-INF\lib\bean.jar

inside the bean.jar should be an entry for:beanWHATEVER.class in directory
com\awl\jspbook\ch04\

JSP files should be in the document root for the site:
tomcat\webapps\examples\jspbook\ch04
Note: Java source for the bean can reside with the classes....but should
technically go into a ....\WEB-INF\src subdirectory.

I agree with your buddy....for the purposes of following examples,
remove or shorten the package !!

-----Original Message-----
From: A mailing list about Java Server Pages specification and reference
[mailto:JSP-INTEREST@java.sun.com] On Behalf Of Roland Dong
Sent: Monday, March 05, 2001 5:42 PM
To: JSP-INTEREST@JAVA.SUN.COM
Subject: Re: Can you help with JSP example?


Thanks a lot, Rohit,

I tried your suggestion, didn't work either. Still get Error 500.

beanexample1.jsp is located under
C:\tomcat\webapps\examples\jspbook\ch04\beanexample1.jsp

Bean1.class is located under
C:\tomcat\webapps\examples\WEB-INF\classes\ch04

Any ideas what goes wrong?

Roland

-----Original Message-----
From: A mailing list about Java Server Pages specification and reference
[mailto:JSP-INTEREST@JAVA.SUN.COM]On Behalf Of kuttappan
Sent: Sunday, March 04, 2001 9:36 PM
To: JSP-INTEREST@JAVA.SUN.COM
Subject: Re: Can you help with JSP example?


Ronald, I haven't read your code fully, but IMHO your package statement
should read jspbook.ch04; and not com.awl.jspbook.ch04;  Hope this helps.

Rohit.
----- Original Message -----
From: "Roland Dong" <RB...@WIU.EDU>
To: <JS...@JAVA.SUN.COM>
Sent: Monday, 05 March, 2001 9:09 AM
Subject: Can you help with JSP example?


> 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 is 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());
>   }
> }
>