I don't know all of the "official" ways to do this but this worked for me:
Note that <jsp1.0> represents the directory in which you unzipped the JSP
reference distribution.
I named my bean .java file "RicksClass.java". The first non-comment line in
the .java file is:
package rbean;
The .java file is located in a directory I created named
<jsp1.0>\examples\WEB-INF\jsp\beans\rbean. It is compiled there and
produces "RicksClass.class".
My jsp page is named "rtest.jsp" and is located in a directory I created
named <jsp1.0>\examples\jsp\rtest.
Inside the .jsp file I have the following line:
<jsp:useBean id="ricky" scope="request" class="rbean.RicksClass" />
I access properties of my class from the .jsp file like this:
<li> The property is: <jsp:getProperty name="ricky"
property="helloProp"/>
I call methods of my class from the .jsp file like this:
<li> The value of PI is:
<%
out.println(ricky.testMethod());
%>
All of the above assumes the defaults are taken in the reference
implementation of JSP 1.0.
I seem to remember that I had to monkey with the CLASSPATH environment
variable in the CLI from which I run "startserver.bat".
Rick Schaeffer
([EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]> )
-----Original Message-----
From: /servlet-interest Paula Lumby [SMTP:[EMAIL PROTECTED]]
Sent: Wednesday, May 19, 1999 2:25 PM
To: [EMAIL PROTECTED]
Subject: JSP classpath and default.cfg
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".
===========================================================================
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".