Reputation: 285
I am playing with a simple struts2 app. It has 2 JSP pages - one 'login.jsp' page and the second page is a simple 'form.jsp'. I use this same form to submit data to the database any number of times. If I successfully login, I display the name of the userid on the 'form.jsp' page. After the first successful login, the userid is displayed on form.jsp using <s:property value="#session['user'].userid" />
, but after the first submit, subsequent displays of form.jsp returns a blank for the userid.
The login and logout pages are SessionAware
, but the Action behind form.jsp simply implements a model object and is not session aware. How do I retain the 'userid' across multiple submit(s)? If anyone could please help me out, I would really appreciate it.
Upvotes: 1
Views: 50
Reputation: 1
How do I retain the 'userid' across multiple submit(s)?
You really need a session variable. Since the multiple submits invoke different requests the variable will be important.
Save the value to the hidden filed like this
<s:hidden name="userId" value="%{#session.user.userId}" multiple="true" />
The name must be camaleCased, so you have the getter and setter to the property. When you come back to the form again it will retrieve the value from the session.
Upvotes: 1