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?

+1


source to share


3 answers


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.

+3


source


You don't have to inject the bean yourself. Let the JSP do it for you



+1


source


change the scope from session to request a fix for you?

0


source







All Articles