1

I have been googling and found that I can remove a session attribute using:

<c:remove var="foo" />

What I want is to clear all session attributes from a JSP, something like this:

<c:forEach  var="item" items="${sessionScope}">
    <c:remove var="${item }" scope="session"/>
</c:forEach>    

The problem is that the code from above gives me this warning

c:remove doesn't support runtime expression

And I can't view the JSP where I put the code.

Is it possible? Is it a good practice to do something like this?

Jessai
  • 947
  • 2
  • 15
  • 35
  • 2
    Why would you do that in a JSP, which is a view component used to generate HTML code? Do that in Java, inside your controller. – JB Nizet Feb 28 '14 at 16:58
  • Ok, so It's a bad practice, I'm a newbie trying JSTL, anyway it's strange that you can remove a session attribute in the view. – Jessai Feb 28 '14 at 17:48
  • 1
    You can do it. Just use a scriplet. <%session.removeAttribute("a");%> But, it is considered a sin. – rickz Mar 01 '14 at 03:09

1 Answers1

1

Because your are iterating through "item" and while iterating it inside loop you are trying to delete.

Better do this logic in java only rather than JSP

Gautam
  • 3,276
  • 4
  • 31
  • 53