Using jsp bean in session
I am using a JSP bean and when I do an assignment to a new object, it gets overwritten in submit to the previous object.
<jsp:useBean id="base" class="com.example.StandardBase" scope="session" />
...
//base object id = 396
base = new Base()
//base object id = 1000
and when re-submitting the page I get
<jsp:useBean id="base" class="com.example.StandardBase" scope="session" />
//base object id = 396
Is there a way to tell the JSP to complete a new job?
source to share
I'm not entirely sure, but I guess it base = new Base()
doesn't update the link stored in the session scope. Therefore, the bean created with the initial <jsp:useBean/>
one still exists, and the one you create manually and then update is not.
Get rid of base = new Base()
it and you will be fine.
If you insist on updating it, you are using HttpSession.setAttribute()
. For example:
session.setAttribute("bean", bean);
I believe the variable is session
automatically created and initialized for you by the JSP engine.
source to share