Tim,

Do you put request.getSession().setAttribute( "user", userbean) in the JSP
or servlet after calling the bean's setter?  It doesn't work in the servlet;
still getting "NULL" returned to the JSP.  Does web.xml need to be modified
and JRUN restarted (I'm a bit fuzzy on when web.xml is required outside of
J2EE applications using EJBs)?

I am trying to model the behavior of the Front Controller pattern
(http://developer.java.sun.com/developer/restricted/patterns/FrontController
.html)
where the ServletFront servlet serves as the database gateway and passes
field values to a JavaBean ("UserBean" in my case) which acts as a Data
Access Object (DAO), accessible to any JSP within session scope, and then
returns control to the FrontController so the correct JSP can be dispatched.

I can't believe I cannot find any code examples to doing what should be a
very common usage of MVC using servlets.  And BTW, if you haven't looked at
the patterns associated with the above URL, the discussion is excellent.
But no code examples (not even in the Java library at
http://developer.java.sun.com/developer/codesamples/).

Thanks!
Mark

----- Original Message -----
From: "Chen, Gin" <[EMAIL PROTECTED]>
Sent: Friday, December 28, 2001 11:39 AM


> U need to add the userbean to the session scope within the servlet.
> This line:
> <jsp:useBean id="user" class="UserBean" scope="session" />
> is looking for userbean in the session scope.. since ur servlet doesnt put
> it there.. it decides to create a new one.
> I use this if i need a bean in a page that will set up a bean for the
> servlet.
> U should use:
>
> UserBean userbean = new UserBean();
> userbean.setSomething("something");
> request.getSession().setAttribute( "user", userbean );
>
> Common mistake.. i do it all the time.
> -Tim
>
> -----Original Message-----
> From: Mark Galbreath [mailto:[EMAIL PROTECTED]]
> Sent: Friday, December 28, 2001 11:42 AM
>
> I've never done this before and I can find no help in any of the Sun
> tutorials.  I'm trying to set the properties in a Bean with a servlet and
> get those properties with a JSP.  I believe I am doing everything
correctly,
> but I'm getting NULLs (no NullPointerExceptions, I'm getting "NULL" as
HTML)
> on the JSP as returns for the Bean's getters.
>
> The Bean DECLARES the properties:
>
> public class UserBean implements serializable {
>     private String something;
>
>     public String getSomething() {
>         return something;
>     }
>     public void setSomething( String thing) {
>         this.something = thing;
>     }
>     ...
> }
>
> The servlet SETS the properties:
>
> ...
> UserBean userbean = new UserBean();
> userbean.setSomething( String string);
> ...
>
> And the JSP GETS the properties:
>
> ...
> <jsp:useBean id="user" class="UserBean" scope="session" />
> <jsp:getProperty name="user" property="something" />
> ...
>
> Pretty straightforward, right?  Why am I getting "NULL" in the JSP instead
> of the string set by the servlet?  Am I missing something in the JSP
> getProperty?  Is the servlet setting the properties correctly?  One
> additional point, the code helper (class/method dot popups) in Forte does
> not display any of UserBean's methods when I type "userbean." (userbean +
> period).

___________________________________________________________________________
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