• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to get result of requet.getAttribute() from jsp?  RSS feed

 
Nakata kokuyo
Ranch Hand
Posts: 472
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi, good day , if i have page1.jsp , and it have request.setAttribute("resultTest"), but when i click on submit button, which act to fire form.action=page2.jsp , and in page2.jsp , why i can't get the result of request.getAttribute("resultTest") ?

can do i resolve this problem ? means i want to use request.getAttribute rather than session.getAttribute() ...thank you for guidance
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66261
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Once the response has been sent to the browser, the request goes out of scope.
 
Nakata kokuyo
Ranch Hand
Posts: 472
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for reply, Bear Bibeault , mind to elaborate more on this ?

can i do something on this in order to use request.getAttribute()?
 
Alwyn Schoeman
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My understanding is that your first jsp presents the user with a form. Pressing the submit button then has the second jsp as its action...

These 2 jsp's are processed as seperate requests and as such do not
share the same request object.

You can use sessions, but you could also just submit the data you want
to go to the second jsp as a parameter in the POST.
 
Nakata kokuyo
Ranch Hand
Posts: 472
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks, Alwyn Schoeman for explain, but due to the parameter passing are list , so i need to apply either session or request.setAttribute("myList"), but it good if i send the list over to page2.jsp with fresh list, in order to avoid keep other previous list, of course i can use session.removeAttribute(), but request.setAttribute will save few line of code like validation and so on

so conclusion, we can't use request.getAttribute() in page2.jsp if we forward setAttribute from page1.jsp ...thank you for guidance anyway

if we use response.sendRedirect() , would it help ?
 
Dhananjay Inamdar
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi


You have to go for JSP Forward tag. As it is working on server side and doesn't create new request object, you will not lose your data.
You will not see URL changing from page1 to page2.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66261
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using a forward is not appropriate for this case.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!