JSP, JavaBeans and Forms scoping question. Strange behaviour?

M

Matt S.

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top