Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Setting request attributes on reloading page  RSS feed

 
Mohan Dinesh Ganti
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a small issue and I feel its solution might be quite easy for anybody who is a little bit more knowledgeable than me.

I have a JSP page that is reloading every 10 seconds. In the page I want to display some information that I set as attributes in the servlet that is forwarding to the page. In the JSP I have the following scriptlet:



I am basically getting the attributes from the request to display them and then setting them again so that the next time the page reloads they will still be available. The problem is that the first time everything is fine but the second time the information is gone. Do you have any idea of way? Any suggestion?

Thanks so much!
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Of course the info is gone. Each time you reload the page you're going to be getting a new request. Any info on the previous request is long gone.

If you want scoped variables to exist beyond the lifetime of the request, they'll need to be placed in session scope.
 
Mohan Dinesh Ganti
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply,

but have you noticed that I am setting those attributes in the request again so that they will be again available once the page is reloaded?

Am I doing something wrong?

Thanks again,

Dinesh
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Once the page is written to the browser, that request is gone, dead, and buried. When the browser makes a new call to the server, a brand new request object will be created.
 
Mohan Dinesh Ganti
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then what should I do to solve the problem?

Thanks,

Dinesh
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you read my original reply? Your answer is there.
 
Vinit Sacheti
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can store them as hiddent variables. And it will be available for the next request.
<% String cmdDesc = (String)request.getAttribute("cmdDesc");
String resourceIdList = (String)request.getAttribute("resourceIdList");
%>
<input type="hidden" name="cmdDesc" value=<%=cmdDesc%>"

For the next reqest, get the value as
request.getParameter("cmdDesc")
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hidden inputs can only be used for string values and is less efficient than using the session.
[ April 09, 2007: Message edited by: Bear Bibeault ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!