Chris Powell wrote:
>
> Hi,
> Can anyone assist me, PLEASE.
> I have created a JSP and included a call to a simple bean which all
> works fine.
> I need to know how within my bean I can call another class/bean?
>
> I am trying to write a validate bean that calls a 'wrapped database
> procedure' class in Oracle.
>
> Any helpful comments would be appreciated.
>
> Thanks
>
> Chris
>
> ___________________________________________________________________________
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

You can call any other class from within a Bean in the same way as you
do in any java code eg
MyNewWierdBean bean = new my.package.MyNewWierdBean();

If you mean who do I get a reference to an existing object from within
the JSP context then you can use the javax.servlet.jsp.PageContext to
find such a reference.
Or use a remote object technology like RMI or CORBRA (using JNDI
lookup).

Or you can pass objects into the JSP session bean's sesion , say for
instance my JSP ("/Docs/hellouser.jsp") made use of the bean below

<jsp:useBean id="mybean" scope="session"
class="kcom.kms.beans.NameHandler" type="kcom.kms.beans.NameHandler" >
</jsp:useBean>

It is a session bean so i could create it from outside the JSP (say in a
servlet) and pass it into the JSP's session, The JSP checks to see if
such a bean is already in existance before it creates one. so I could
pass one in as follows

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import kcom.kms.beans.NameHandler;

public class TestServlet2 extends HttpServlet {

    NameHandler mybean= new NameHandler();

    public void init(ServletConfig config) throws ServletException {
        super.init(config);

        mybean.setUsername("Yes");
    }

    public void doGet(HttpServletRequest req, HttpServletResponse res)
        throws ServletException, IOException {

        HttpSession session = req.getSession(true);
        session.putValue("mybean", mybean);
        String whereTo=HttpUtils.getRequestURL(req).toString();
        session.putValue("where.to",whereTo);

        String test = new String("wayhay");
        session.putValue("test.string", test);
        RequestDispatcher rd= \

getServletContext().getRequestDispatcher(res.encodeURL("/Docs/hellouser.jsp"));

        try {
            rd.forward(req,res);
        }
        catch (ServletException se) {
            res.setContentType("text/plain");
            PrintWriter out= res.getWriter();
            out.println("ERROR in Forward\n\n"+se+"\n");
            out.close();
        }
    }

     public void doPost(HttpServletRequest req, HttpServletResponse res)
         throws ServletException, IOException {
         doGet(req,res);
     }
}


Hope it helped

Karl

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to