You would need the following:
<%@ page language="java" import="beans.FormBean" contentType="text/html" %>
<jsp:useBean id="FormBean" class="beans.FormBean" scope="request" />

Also, is your FormBean.class in "webapps\xxx\WEB-INF\classes\beans" directory?

Roger Whitcomb
Computer Associates
Senior Software Engineer
Development
Phone: +1 408 965 8653
FAX: +1 408 965 8805
[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]> 


-----Original Message-----
From: eric [mailto:[EMAIL PROTECTED]]
Sent: Thursday, July 11, 2002 9:44 AM
To: [EMAIL PROTECTED]
Subject: Cannot use bean from jsp, but servlet ok. I'm dying!


Help. Absolutely stuck. Tomcat cannot find my bean classes no matter what
when called from jsp pages. From within servlets no problem.

Here is the jsp
---------------
<%@ include file="pub_hdr.html" %>
<jsp:usebean id="FormBean" class="beans.FormBean" scope="request" />
<form>
<input type="text" name="userName" value="<% =FormBean.getUserName() %>">
<%= FormBean.getErrorMsg("userName") %>
</form>
<%@ include file="pub_ftr.html" %>

Here is the bean
----------------
package beans;
import java.util.*;
import java.io.Serializable;
public class FormBean implements Serializable {
  public String userName;
  public FormBean() {}

  public String getUserName() {
    return this.userName;
  }
  public void setUserName(String uname) {
    this.userName = uname;
  }
}

NO MATTER WHAT, as soon as I access the jsp page. This error comes up.
Generated servlet error: C:\jwsdp-1_0\work\Standard
Engine\localhost\messagesmith\en\users$jsp.java:126: Undefined variable or
class name: FormBean out.print( FormBean.getUserName() );

It certainly seems that TC cannot find the FormBean class which lives here:
C:\jwsdp-1_0\webapps\project\WEB-INF\classes\beans.
I've changed that scope attribute to application or page, but it doesn't
change.
With TC3.x I had to do some configuration in the conf/server.xml file, but
this doesn't seem necessary w/ TC4. All the same I've adding the following
context to the server.xml, but it doesn't help.
<Context path="/project"
  docBase="webapps/project"
  debug="0"
  reloadable="true" />

Anyone have any ideas? It is killing me. Again, I can instantiate the
FormBean class from within servlets, but not from JSP.

Env:
====
Win2k Server, jdk1.4.0_01, TC4.0
Classpath=.;C:\jwsdp-1_0\common\lib\servlet.jar;C:\jwsdp-1_0\webapps\project
\WEB-INF\classes;C:\jfreechart-0.9.1\jars\jcommon-0.6.3.jar;C:\jfreechart-0.
9.1\jars\jfreechart-0.9.1.jar;
TOMCAT_HOME=C:\jwsdp-1_0
CATALINA_HOME=C:\jwsdp-1_0
JAVA_HOME=C:\j2sdk1.4.0_01

Reply via email to