请求分派器转发和 servlet 链接之间的区别 [英] Difference between request dispatcher forward and servlet chaining

查看:50
本文介绍了请求分派器转发和 servlet 链接之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请求分派器的转发方法和servlet链接的概念有什么区别?

What is the difference between request dispatcher's forward method and the concept of servlet chaining?

例子

RequestDispatcher rd= req.getRequestDispatcher("pathToServlet");
rd.forward(req,resp);

这样做是在不涉及客户端(浏览器)交互的情况下转发请求.但是我们可以使用 Servlet Chaining 来达到同样的效果吗?如果可以,那有什么区别?.

What this does is forwards the request without involving the client(browser) interaction. But can we achieve the same using Servlet Chaining?. If we can then what is the difference?.

推荐答案

没有什么不同.servlet 链接"只是在 servlet 过滤器不存在的黑暗 J2EE 1.1/1.2 时代创造的一个术语.实际上,这基本上是使用 RequestDispatcher#forward() 从一个 servlet 转发到另一个 servlet 的方法(并确保响应尚未提交,否则会导致 IllegalStateException).

It's not different. "Servlet chaining" is just a term coined in dark J2EE 1.1/1.2 ages when servlet filters didn't exist. Indeed, it's basically the approach of using RequestDispatcher#forward() to forward from one to other servlet (and ensuring that the response isn't already committed as that would otherwise result in IllegalStateException).

自 J2EE 1.3(Servlet 2.3,十年之前!)servlet 过滤器a> 被引入,这使得这个过程变得更加干净和容易.从那时起,Servlet 链接"就受到了反对,并且通常被标记为糟糕的设计".如今,您最终只想得到一个前端控制器 servlet 和多种业务模型.

Since J2EE 1.3 (Servlet 2.3, over a decade ago already!) servlet filters were introduced which made the process so much more clean and easy. Since then, "Servlet chaining" is frowned upon and usually marked as "bad design". These days, you'd ultimately like to end up with only one front controller servlet and several business models.

这篇关于请求分派器转发和 servlet 链接之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆