JSP JavaBeans problem in scope="session" attribute

Discussion in 'Java' started by jrefactors@hotmail.com, Dec 20, 2004.

  1. Guest

    I use scope="session" in <jsp:useBean id="user"
    class="com.proj1.model.User" scope="session"/>,
    and I expect the bean name user doesn't need to redeclare in other
    pages,
    because the bean is available throughout the session.

    User Id = 1234 is shown in test1.jsp, but when the user click the
    submit button, then it has error

    Parsing of JSP File '/test/test2.jsp' failed:
    /test/test2.jsp(1): "user" is not a defined bean variable on this page
    probably occurred due to an error in /test/test2.jsp line 1:
    <H1>User ID = <jsp:getProperty name="user" property="userId"/></H1>

    test1.jsp
    =========
    <jsp:useBean id="user" class="com.proj1.model.User" scope="session"/>
    <jsp:setProperty name="user" property="userId" value="1234"/>
    <H1>User ID = <jsp:getProperty name="user" property="userId"/></H1>
    <html>
    <head>
    </head>
    <body>
    <form action="test2.jsp" method="POST">
    <input type="submit" value="submit here">
    </form>
    </body>
    </html>

    test2.jsp
    =========
    <H1>User ID = <jsp:getProperty name="user" property="userId"/></H1>
    any ideas? please advise.

    thanks!!
     
    , Dec 20, 2004
    #1
    1. Advertising

  2. wrote:
    I expect the bean name user doesn't need to redeclare in other
    > pages,
    > because the bean is available throughout the session.



    You still need to have the bean tag in your other pages though. The
    "session" means that a new bean won't be created on another page,
    rather the bean you created on the first page will be maintained.
     
    Robert kebernet Cooper, Dec 20, 2004
    #2
    1. Advertising

  3. Guest


    > You still need to have the bean tag in your other pages though. The
    > "session" means that a new bean won't be created on another page,
    > rather the bean you created on the first page will be maintained.


    What do you mean by need the bean tag?

    Do I need to declare the following in page2.jsp also?
    <jsp:useBean id="user" class="com.proj1.model.User" scope="session"/>
     
    , Dec 20, 2004
    #3
  4. Guest


    > You still need to have the bean tag in your other pages though. The
    > "session" means that a new bean won't be created on another page,
    > rather the bean you created on the first page will be maintained.

    what do you mean by bean tag? <jsp:useBean id="user"> ??
     
    , Dec 20, 2004
    #4
  5. wrote:

    >>You still need to have the bean tag in your other pages though. The
    >>"session" means that a new bean won't be created on another page,
    >>rather the bean you created on the first page will be maintained.

    >
    >
    > What do you mean by need the bean tag?
    >
    > Do I need to declare the following in page2.jsp also?
    > <jsp:useBean id="user" class="com.proj1.model.User" scope="session"/>


    Yes, exactly so. The main purpose of a <jsp:useBean> action is to
    _declare_ a bean to the rest of the page implementation, and every page
    must declare all the beans it uses. The action will create a bean of
    the specified type, bound to the specified name, and assigned to the
    appropriate scope if none yet exists, but that is best considered a side
    effect rather than the goal of the action.


    John Bollinger
     
    John C. Bollinger, Dec 20, 2004
    #5
  6. J2EEStar Guest

    Hi,

    Try this below steps........

    first try to forward the Request/Response Object from test1.jsp page to
    test2.jsp page. then try to get property as u did.

    J2EEStar.


    wrote:
    > I use scope="session" in <jsp:useBean id="user"
    > class="com.proj1.model.User" scope="session"/>,
    > and I expect the bean name user doesn't need to redeclare in other
    > pages,
    > because the bean is available throughout the session.
    >
    > User Id = 1234 is shown in test1.jsp, but when the user click the
    > submit button, then it has error
    >
    > Parsing of JSP File '/test/test2.jsp' failed:
    > /test/test2.jsp(1): "user" is not a defined bean variable on this

    page
    > probably occurred due to an error in /test/test2.jsp line 1:
    > <H1>User ID = <jsp:getProperty name="user" property="userId"/></H1>
    >
    > test1.jsp
    > =========
    > <jsp:useBean id="user" class="com.proj1.model.User" scope="session"/>
    > <jsp:setProperty name="user" property="userId" value="1234"/>
    > <H1>User ID = <jsp:getProperty name="user" property="userId"/></H1>
    > <html>
    > <head>
    > </head>
    > <body>
    > <form action="test2.jsp" method="POST">
    > <input type="submit" value="submit here">
    > </form>
    > </body>
    > </html>
    >
    > test2.jsp
    > =========
    > <H1>User ID = <jsp:getProperty name="user" property="userId"/></H1>
    > any ideas? please advise.
    >
    > thanks!!
     
    J2EEStar, Dec 21, 2004
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chris Beach
    Replies:
    0
    Views:
    586
    Chris Beach
    Sep 8, 2003
  2. matt

    Javabeans and JSP's

    matt, Jan 24, 2004, in forum: Java
    Replies:
    2
    Views:
    358
  3. Philip McKee
    Replies:
    2
    Views:
    1,379
    Philip McKee
    Apr 20, 2004
  4. Matt S.
    Replies:
    0
    Views:
    405
    Matt S.
    May 4, 2004
  5. Replies:
    2
    Views:
    523
Loading...

Share This Page