且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在JSTL中设置cookie

更新时间:2023-01-07 17:37:43

您不能使用JSTL设置cookie。 JSTL 没有此功能的任何标签。 JSTL在生成HTTP响应期间运行,而在生成HTTP响应之前,需要在HTTP响应头中设置一个Cookie。

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.

使用预处理 servlet 过滤器,其中您只需调用 response.addCookie()

Use a preprocessing servlet or filter instead wherein you can just call response.addCookie()