I've been restating the following question and getting a variety of answers.
Many thanks to James and Gillard, who have treid to be very helpful. However I
am still stuck. Here is the question again.
I am using the JSP 1.0 refernce implementation and trying to use with the
original default.cfg, partly because I do not understand server.webapp and
servet.app lines.
I have a JSP that want to use a bean. The abolute path to the JSP is
X;\jsp1.0\webpages\UseBean.jsp.
Here is the entire JSP ( it slavishly follows the example
examples\jsp\cal\cal2.jsp:
<html>
<head>
<title>A test</title>
<body>
<jsp:useBean id="namebean" scope="application" class="MyBean" />
<p>This is a jsp that reads a name from a bean.</p>
<h1>Hello <%= nameBean.getName() %> </h1>
<hr>
<the end>
</body>
</html>
My MyBean class is pretty simple ( and in the default package):
class MyBean {
private String name;
MyBean() { name = "Paula"; }
String getName() { return name; }
}
One question is where to put the MyBean.class file?
On second thought perhaps my question should be, what should be the scope
attribute in the usebean tag. All the scopes seem to get the bean from a
session, context or whatever. But what if I want to start the conversation with
JSP.
So, what I did next was put MyBean.class and .java into the
jsp1.0/webpages/servlets/ directory along with a servlet that is intended to
load the bean into the ServletContext. Here is the class:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class UseBean extends HttpServlet
{
public void doGet( HttpServletRequest req,
HttpServletResponse res )
throws IOException {
try {
MyBean aName = (MyBean) java.beans.Beans.instantiate(
getClass().getClassLoader(),"MyBean");
ServletContext sc = getServletContext();
sc.setAttribute( "namebean", aName);
RequestDispatcher rd = sc.getRequestDispatcher("/UseBean.jsp");
rd.forward( req, res );
} catch ( Exception e ) {
System.out.println(" EXCEPTION: " + e.getMessage());
}
}
}
The result?
I start the server issue the UseBean URL to the browser. The result: is an
IllegalAccessException in Beans.instantiate().
Can anyone help?
Paula Lumby
IBM VisualAge for Java/C++/RPG Services
tel: 448-2517 (T/L) 778-2517
Room: 2G42C 2G/KB4/1150/TOR
e-mail: [EMAIL PROTECTED]
External Address:
IBM Toronto Laboratory
1150 Eglinton Avenue East
Toronto, Ontario, Canada, M3C 1H7
FAX: (416) 448-4414
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JSP-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".