如何从标记库内部停止进一步的请求执行?
基本上,我们想要创建一个可以将请求执行转发到另一个页面的标记库,类似于
。我们如何防止 JSP 页面的其余部分从 taglib 内执行?
Basically, we want to create a taglib that can possibly forward request execution to another page, similar to <jsp:forward />
. How can we prevent the rest of the JSP page from executing from within the taglib?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您不应该在标记库中执行此操作。而是在 Servlet 或 过滤,在将任何位发送到响应之前。否则,您可能会遇到
IllegalStateException:response already commit
麻烦。You shouldn't be doing this in a taglib. Rather do it in a Servlet or Filter, before any bit is been sent to the response. Otherwise you will possible get into
IllegalStateException: response already committed
troubles.对我来说,以下几行效果很好:
For me the following lines worked quite well:
如果您不想在将控制权传递给另一个页面后继续处理原始页面,那么最好使用重定向而不是转发。
这将重定向到新页面并停止处理旧页面。
但是 - 仅当您尚未向响应正文写入任何内容(即未将任何数据发送回客户端)时,重定向才可用。
If you don't want to continue processing the original page after passing control to another you are better off using a redirect rather than a forward.
This will redirect to the new page and stop processing the old one.
However - redirects are only usable if you have not written anything to the response body yet (i.e. not sent any data back to the client).