[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index] [Home]

java.lang.ClassCastException


I'm having some trouble working with beans in JSP pages. Or maybe I just don't
understand how this is supposed to work.  Anyway, I'd appreciate if anyone could
shed some light on me.

I have a test bean (TestBean.java) that I'm calling in my test.jsp page.  (it's
in a 'servlet' directory in my repository) Here's the TestBean.java file:
---------------------------------------------------
package servlet;
import java.io.Serializable;

public class TestBean implements Serializable {
    private String name = "Mark";

    public TestBean() { }

    public void setName(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }
}
---------------------------------------------------
Now, when I use it the following way, it works:

test.jsp:
---------------------------------------------------
<html>
<head>
<title>Test</title>
</head>
<body bgcolor=#ffffff>

<BEAN name="tb" type="servlet.TestBean"></BEAN>
<% tb.setName("Elbertoad"); %>
<%= tb.getName() %>

</body>
</html>
---------------------------------------------

However, when I try the following,

test.jsp (doesn't work):
---------------------------------------------------
<html>
<head>
<title>Test</title>
</head>
<body bgcolor=#ffffff>

<%@ import = "servlet.TestBean" %>
<BEAN name="tb" type="TestBean"></BEAN>
<% tb.setName("Elbertoad"); %>
<%= tb.getName() %>

</body>
</html>
---------------------------------------------------

I get the following stack trace in my error log:

---------------------------------------------------
[02/06/1999 17:32:21:705 PDT] java.lang.ClassCastException: TestBean
        at _jsp._sites._rmy._htdocs._test_2ejsp.service(_test_2ejsp.java:21)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:588)
        at org.gjt.jsp.JSPServlet.service(JSPServlet.java:224)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:588)
        at
org.apache.jserv.JServConnection.processRequest(JServConnection.java:335)
        at org.apache.jserv.JServConnection.run(JServConnection.java:197)
        at java.lang.Thread.run(Thread.java)
---------------------------------------------------

Can anybody shed some light on this?  TIA.

Rich

-------------------------
Richard M. Yumul
mailto:chewie@dtai.com
DTAI Incorporated
http://www.dtai.com
(619)542-1700 · fax:(619)542-8675