Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSTL Question about c:set ... scope="request"

 
Nadine McKenzie
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have this code...
<logic resent name="results" scope="request">
<c:set var="resultsInRequest" scope="request" value="requestScope.results" />
</logic resent>
<logic resent name="search" scope="request">
<c:set var="searchInRequest" scope="request" value="requestScope.search"/>
</logic resent>

Since I'm setting my scope as request vs page, I would expect that when submitting this page that both resultsInRequest and searchInRequest could be retrieved from the HttpServletRequest request.getAttribute("searchInRequest").

Does anybody know what I'm doing wrong? ThanKs!
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64613
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a fundamental concept in HTTP. The request that you use to render a page and send it to the browser has nothing to do with the request that gets created when that page is submitted.

Anything that you put onto request scope goes bye-bye as soon as the response is sent to the browser.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64613
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
P.S. Using the 'disable smilies' checkbox when posting code will make your tags look less bratty.
 
Nadine McKenzie
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is what I thought. But it is logically obtuse. If it were set to "session" it would die when the session timesout. If it were "page" it would die when the page dies. It would have been better if setting the scope to "request" would behave as request.setAttribute. Oh well...
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64613
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But it is logically obtuse.


Not at all. Request scope extends for the lifetime of the request. Page scope extends for the lifetime of a JSP page. Session scope extends for the lifetime of a session. And application scope extends for the lifetime of an application context.

What's obtuse about it?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic