You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Mark Liu <ma...@yahoo.com> on 2003/05/23 10:11:52 UTC

At my wits' end: Using JavaBean in JSP

I searched the Web for a while, and found that quite
many people had the same problem.  But no one solution
I found on the Web solved the problem.

The problem is that my JSP page just can't get
compiled. And here are the exceptions:

org.apache.jasper.JasperException:
coreservlets.StringBean
  [snip]
java.lang.ClassNotFoundException:
coreservlets.StringBean
  [snip]

Before you take it for granted that it's a path
problem, I do have the correct path for everything!

I did try <%@ page import="coreservlets.StringBean" %>
at the top of the jsp page, it does not help!

*** The Bean class is from *************
*** Marty Hall's Core Servlets *********
*** and so is the StringBean.jsp***

package coreservlets;

public class StringBean {
  private String message = "No message specified";

  // Some people suggested that I
  // add the default constructor, which
  // does not help solve the problem.

  public StringBean()
  {}

  public String getMessage() {
    return(message);
  }

  public void setMessage(String message) {
    this.message = message;
  }
}

*** And the JSP page is right here ****

<!-- this import below does not help -->
<%@ page import="coreservlets.StringBean" %> 

<HTML>
<HEAD>
<TITLE>Using JavaBeans with JSP</TITLE>
</HEAD>

<BODY>

<TABLE BORDER=5 ALIGN="CENTER">
  <TR><TH CLASS="TITLE">
      Using JavaBeans with JSP</TABLE>
 
<jsp:useBean id="stringBean"
class="coreservlets.StringBean" />

<OL>
<LI>Initial value (getProperty):

<!-- the problem persists even if I do
     name="coreservlets.stringBean" below
-->

    <I><jsp:getProperty name="stringBean" 
                        property="message" /></I>

<LI>Initial value (JSP expression):
    <I><%= stringBean.getMessage() %></I>
<LI><jsp:setProperty name="stringBean" 
                     property="message" 
                     value="Best string bean: Fortex"
/>
    Value after setting property with setProperty:
    <I><jsp:getProperty name="stringBean" 
                        property="message" /></I>

<LI><% stringBean.setMessage("My favorite: Kentucky
Wonder"); %>
    Value after setting property with scriptlet:
    <I><%= stringBean.getMessage() %></I>
</OL>
             
</BODY>
</HTML>
*** end of the JSP ***

On the Solaris system where I run tomcat4.1.24, the
Bean file is at
/export/home/tomcat4.1.24/webapps/ROOT/WEB-INF/classes/corsevlets/StringBean.java

and the JSP is at
/export/home/tomcat4.1.24/webapps/ROOT/StringBean.jsp

My tomcat server is running well, servlets work just
great.

This is the first time I try working with JavaBeans
and got so much trouble.  Really do not understand why
I am getting those exceptions.  Any idea please?


__________________________________
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.
http://search.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: At my wits' end: Using JavaBean in JSP

Posted by William Wragg <wi...@datapro.co.uk>.
Jasper compiles my Beans for me. What I do is clear out the 
$CATALINA_HOME/work/Standalone/localhost/MyApp and then when Japser 
compiles the JSP's for the first time and there are no classes (or the java 
source has changed) for the Bean, it will compile the Bean for me when it 
is used in a page. This is using 4.0.4 is it different for later versions?

At 09:59 23/05/2003, you wrote:

>If this file is correct (typo excepted)
>/export/home/tomcat4.1.24/webapps/ROOT/WEB-INF/classes/corsevlets/StringBean.java
>then the problem is that you need to deploy the compiled class file and 
>not the source. Jasper doesn't compile beans for you.
>
>Mark Liu wrote:
>>I searched the Web for a while, and found that quite
>>many people had the same problem.  But no one solution
>>I found on the Web solved the problem.
>>The problem is that my JSP page just can't get
>>compiled. And here are the exceptions:
>>org.apache.jasper.JasperException:
>>coreservlets.StringBean
>>   [snip]
>>java.lang.ClassNotFoundException:
>>coreservlets.StringBean
>>   [snip]
>>Before you take it for granted that it's a path
>>problem, I do have the correct path for everything!
>>I did try <%@ page import="coreservlets.StringBean" %>
>>at the top of the jsp page, it does not help!
>>*** The Bean class is from *************
>>*** Marty Hall's Core Servlets *********
>>*** and so is the StringBean.jsp***
>>package coreservlets;
>>public class StringBean {
>>   private String message = "No message specified";
>>   // Some people suggested that I
>>   // add the default constructor, which
>>   // does not help solve the problem.
>>   public StringBean()
>>   {}
>>   public String getMessage() {
>>     return(message);
>>   }
>>   public void setMessage(String message) {
>>     this.message = message;
>>   }
>>}
>>*** And the JSP page is right here ****
>><!-- this import below does not help -->
>><%@ page import="coreservlets.StringBean" %>
>><HTML>
>><HEAD>
>><TITLE>Using JavaBeans with JSP</TITLE>
>></HEAD>
>><BODY>
>><TABLE BORDER=5 ALIGN="CENTER">
>>   <TR><TH CLASS="TITLE">
>>       Using JavaBeans with JSP</TABLE>
>>
>><jsp:useBean id="stringBean"
>>class="coreservlets.StringBean" />
>><OL>
>><LI>Initial value (getProperty):
>><!-- the problem persists even if I do
>>      name="coreservlets.stringBean" below
>>-->
>>     <I><jsp:getProperty 
>> name="stringBean"                         property="message" /></I>
>><LI>Initial value (JSP expression):
>>     <I><%= stringBean.getMessage() %></I>
>><LI><jsp:setProperty 
>>name="stringBean"                      property="message" 
>>      value="Best string bean: Fortex"
>>/>
>>     Value after setting property with setProperty:
>>     <I><jsp:getProperty 
>> name="stringBean"                         property="message" /></I>
>><LI><% stringBean.setMessage("My favorite: Kentucky
>>Wonder"); %>
>>     Value after setting property with scriptlet:
>>     <I><%= stringBean.getMessage() %></I>
>></OL>
>>
>></BODY>
>></HTML>
>>*** end of the JSP ***
>>On the Solaris system where I run tomcat4.1.24, the
>>Bean file is at
>>/export/home/tomcat4.1.24/webapps/ROOT/WEB-INF/classes/corsevlets/StringBean.java
>>and the JSP is at
>>/export/home/tomcat4.1.24/webapps/ROOT/StringBean.jsp
>>My tomcat server is running well, servlets work just
>>great.
>>This is the first time I try working with JavaBeans
>>and got so much trouble.  Really do not understand why
>>I am getting those exceptions.  Any idea please?
>>
>>__________________________________
>>Do you Yahoo!?
>>The New Yahoo! Search - Faster. Easier. Bingo.
>>http://search.yahoo.com
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>
>
>
>---
>Incoming mail is certified Virus Free.
>Checked by AVG anti-virus system (http://www.grisoft.com).
>Version: 6.0.483 / Virus Database: 279 - Release Date: 19/05/2003

Re: At my wits' end: Using JavaBean in JSP

Posted by Jon Wingfield <jo...@mkodo.com>.
If this file is correct (typo excepted)
/export/home/tomcat4.1.24/webapps/ROOT/WEB-INF/classes/corsevlets/StringBean.java
then the problem is that you need to deploy the compiled class file and 
not the source. Jasper doesn't compile beans for you.

Mark Liu wrote:
> I searched the Web for a while, and found that quite
> many people had the same problem.  But no one solution
> I found on the Web solved the problem.
> 
> The problem is that my JSP page just can't get
> compiled. And here are the exceptions:
> 
> org.apache.jasper.JasperException:
> coreservlets.StringBean
>   [snip]
> java.lang.ClassNotFoundException:
> coreservlets.StringBean
>   [snip]
> 
> Before you take it for granted that it's a path
> problem, I do have the correct path for everything!
> 
> I did try <%@ page import="coreservlets.StringBean" %>
> at the top of the jsp page, it does not help!
> 
> *** The Bean class is from *************
> *** Marty Hall's Core Servlets *********
> *** and so is the StringBean.jsp***
> 
> package coreservlets;
> 
> public class StringBean {
>   private String message = "No message specified";
> 
>   // Some people suggested that I
>   // add the default constructor, which
>   // does not help solve the problem.
> 
>   public StringBean()
>   {}
> 
>   public String getMessage() {
>     return(message);
>   }
> 
>   public void setMessage(String message) {
>     this.message = message;
>   }
> }
> 
> *** And the JSP page is right here ****
> 
> <!-- this import below does not help -->
> <%@ page import="coreservlets.StringBean" %> 
> 
> <HTML>
> <HEAD>
> <TITLE>Using JavaBeans with JSP</TITLE>
> </HEAD>
> 
> <BODY>
> 
> <TABLE BORDER=5 ALIGN="CENTER">
>   <TR><TH CLASS="TITLE">
>       Using JavaBeans with JSP</TABLE>
>  
> <jsp:useBean id="stringBean"
> class="coreservlets.StringBean" />
> 
> <OL>
> <LI>Initial value (getProperty):
> 
> <!-- the problem persists even if I do
>      name="coreservlets.stringBean" below
> -->
> 
>     <I><jsp:getProperty name="stringBean" 
>                         property="message" /></I>
> 
> <LI>Initial value (JSP expression):
>     <I><%= stringBean.getMessage() %></I>
> <LI><jsp:setProperty name="stringBean" 
>                      property="message" 
>                      value="Best string bean: Fortex"
> />
>     Value after setting property with setProperty:
>     <I><jsp:getProperty name="stringBean" 
>                         property="message" /></I>
> 
> <LI><% stringBean.setMessage("My favorite: Kentucky
> Wonder"); %>
>     Value after setting property with scriptlet:
>     <I><%= stringBean.getMessage() %></I>
> </OL>
>              
> </BODY>
> </HTML>
> *** end of the JSP ***
> 
> On the Solaris system where I run tomcat4.1.24, the
> Bean file is at
> /export/home/tomcat4.1.24/webapps/ROOT/WEB-INF/classes/corsevlets/StringBean.java
> 
> and the JSP is at
> /export/home/tomcat4.1.24/webapps/ROOT/StringBean.jsp
> 
> My tomcat server is running well, servlets work just
> great.
> 
> This is the first time I try working with JavaBeans
> and got so much trouble.  Really do not understand why
> I am getting those exceptions.  Any idea please?
> 
> 
> __________________________________
> Do you Yahoo!?
> The New Yahoo! Search - Faster. Easier. Bingo.
> http://search.yahoo.com
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> 




---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: At my wits' end: Using JavaBean in JSP: sorry for a typo

Posted by Mark Liu <ma...@yahoo.com>.
Sorry, in the previous message I have a typo
"corsevlets".

Please note that it is just a typo in that message.  I
do have the correct spelling "coreservlets" on my
system.

> On the Solaris system where I run tomcat4.1.24, the
> Bean file is at
>
/export/home/tomcat4.1.24/webapps/ROOT/WEB-INF/classes/corsevlets/StringBean.java


__________________________________
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.
http://search.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org