How to set a cookie in JSTL

大憨熊 提交于 2020-01-03 17:17:08

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!