JSP, JavaBeans and Forms scoping question. Strange behaviour?

Discussion in 'Java' started by Matt S., May 4, 2004.

  1. Matt S.

    Matt S. Guest

    Hello all,

    I simply want to write a JSP that fills in the fields of a javabean
    from a form, and be able to access the bean for the rest of the
    session. My JSP code looks like this:

    <jsp:useBean id="numbean" class="test.TestBean" scope="session">
    <jsp:setProperty name="numbean" property="*"/>
    </jsp:useBean>

    <html>
    <body>


    <form method=post>
    <input type="text" name="num"/>
    <input type="submit" value="Submit"/>
    </form>

    <p><jsp:getProperty name="numbean" property="num"/></p>
    </body>
    </html>

    My bean code is similarly simple:

    public class TestBean {

    private int num = 0;

    public TestBean() {
    }

    public int getNum() {
    return this.num;
    }

    public void setNum(int num) {
    this.num = num;
    }

    }

    Now, here is the thing, with the above JSP, the num property in the
    bean never seems to change. However, if I change the scope to 'page',
    then it seems to work fine, changing the property whenever I Submit
    the form. What is going on here? Am I missing something simple?

    Thanks for the help,

    Matt
     
    Matt S., May 4, 2004
    #1
    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:
    601
    Chris Beach
    Sep 8, 2003
  2. matt

    Javabeans and JSP's

    matt, Jan 24, 2004, in forum: Java
    Replies:
    2
    Views:
    368
  3. Olinga K. Abbott

    error using JSP, Javabeans, and Tomcat

    Olinga K. Abbott, Jan 12, 2006, in forum: Java
    Replies:
    3
    Views:
    1,199
    Olinga K. Abbott
    Jan 14, 2006
  4. Replies:
    2
    Views:
    541
  5. Chris Beach
    Replies:
    1
    Views:
    245
    Jim Ley
    Sep 8, 2003
Loading...

Share This Page