为什么在Struts1中有Servlet,而在Struts2中却有Filter [英] Why in Struts1 there is Servlet where as in case of Struts2 there is Filter

查看:98
本文介绍了为什么在Struts1中有Servlet,而在Struts2中却有Filter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

前控制器是一个Servlet,但在Struts2中,它是一个过滤器.将其更改为过滤器的可能原因是什么?

The front-controller was a Servlet but in Struts2, it is a filter. What is the possible reason to change it to a filter?

推荐答案

(这是观点,您需要询问WebWork的原始作者.)

(This is opinion, you'd need to ask the original WebWork authors.)

IMO,将请求包装在过滤器中更加直观,因为这是过滤器的设计目的.

IMO it's a bit more intuitive to wrap requests inside a filter, since that's what filters were designed for.

关于从过滤器提供资源的有效性一直存在争议.规范指出:

There has been debate about the validity of serving resources from a filter. The spec states:

过滤器通常不会像servlet那样创建响应或响应请求, 而是他们修改或调整对资源的请求,然后修改或 调整资源的响应.

Filters do not generally create a response or respond to a request as servlets do, rather they modify or adapt the requests for a resource, and modify or adapt responses from a resource.

有些人声称(尤其是一些WebSphere支持票,有时是我本人,然后在

Some have claimed (particularly some WebSphere support tickets, and occasionally myself before re-reading the spec during an email thread on the Struts User mailing list) that the spec disallowed Struts 2's filter usage, but it's clear that nothing disallows their usage in this way.

过滤器通过使用<filter>配置下的<dispatch>元素,可以在处理其他类型的请求(转发,包含和容器错误)时提供更大的灵活性.

Filters allow more flexibility in handling other types of requests (forwards, includes, and container errors) by using the <dispatch> element under <filter> configuration.

请注意,它最初是 在WebWork中的一个servlet -您可以查看提交日志以找出发生更改的原因,但是很久以前,大约7年以上.

Note that originally it was a servlet in WebWork--you may be able to look at the commit logs to ferret out a reason whenever it was the change occurred, but it was quite awhile ago, on the order of 7+ years.

这篇关于为什么在Struts1中有Servlet,而在Struts2中却有Filter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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