问题
I am trying to achieve the below but not sure if its possible and what should the syntax be ?
<c:if condition is true>
<c:set cookie using JSTL>
</c:if>
I am thinking ,since cookie is only set on client side and JSTL is used for doing things on server side, it cannot be done.
回答1:
You can't set a cookie using JSTL. JSTL doesn't have any tags for this functionality. JSTL runs during generating the HTTP response, while a cookie needs to be set in the HTTP response header long before generating the HTTP response. There's otherwise means of an illegal state.
Use a preprocessing servlet or filter instead wherein you can just call response.addCookie()
来源:https://stackoverflow.com/questions/10293825/how-to-set-a-cookie-in-jstl