0

I have following JSTL tag in one of the JSPs:

<c:forEach items="${customerList}" var="cust" varStatus="current">

customerList has been set as session as well as request attribute in 2 different JAVA files:

JAVA file 1 gets called first which has following code:

WebUtils.setSessionAttribute(request, "customerList", VAR1);

After that JAVA file2 gets called which has this:

request.setAttribute("customerList", VAR2);

Then, the JSP is called which refer customerList as stated initially. Now my question is, whether the JSP will take customerList value as VAR1 OR VAR2?

I think it will take VAR1 as it's set in bigger scope i.e. 'session' as compared to 'request'; even if request attribute is set later.

What do you think?

Thanks in advance!!

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Satej Koli
  • 79
  • 2
  • 15
  • Thanks BalusC. I did not notice it before. And I also understood that if request attribute value (VAR2) is NULL, then it will go for the session attribute. Am I correct? – Satej Koli Feb 11 '16 at 09:15

1 Answers1

0

Theoretically, both values will persist till you are serving same request under same session.

Because though you are using same key i.e. 'customerList' its scope is different (session and request) that means internally 2 different variables are created (not exactly but assume for clarity :) ).

Hence it depends on you, which one do you call. If you call WebUtil.getSessionAttribute then VAR1 will be the output and in case of request.getAttribute() VAR2 will be the output.

I haven't tested it though.

Suyash
  • 525
  • 1
  • 6
  • 10