[英]WebRequest and HttpServletRequest in Spring MVC
What is the difference between the two? 两者有什么区别? Both have a
getParameter
method as well as setAttribute
method, then where comes the difference between the two? 两者都有
getParameter
方法以及setAttribute
方法,那么两者之间的差异在哪里呢?
1) Which one is better to use in general? 1)哪一个更好用?
2) Please explain specific scenarios where they can be used. 2)请解释可以使用它们的具体方案。
The javadoc of WebRequest is pretty clear on the subject: WebRequest的javadoc在这个主题上非常明确:
Generic interface for a web request.
Web请求的通用接口。 Mainly intended for generic web request interceptors, giving them access to general request metadata, not for actual handling of the request.
主要用于通用Web请求拦截器,使其可以访问一般请求元数据,而不是实际处理请求。
(emphasis mine). (强调我的)。
The javadoc links to WebRequestInterceptor, which says: javadoc链接到WebRequestInterceptor,它说:
Interface for general web request interception.
一般Web请求拦截的接口。 Allows for being applied to Servlet request as well as Portlet request environments, by building on the WebRequest abstraction.
通过构建WebRequest抽象,允许应用于Servlet请求以及Portlet请求环境。
So, basically, you should not use WebRequest except in a WebRequestInterceptor. 所以,基本上,除了WebRequestInterceptor之外,你不应该使用WebRequest。 And they introduced this interface in order to be able to write interceptors that apply to servlets and portlets.
他们引入了这个接口,以便能够编写适用于servlet和portlet的拦截器。 Other than that, if you really need access to the request in Spring MVC controllers, you should use the standard HttpServletRequest.
除此之外,如果您真的需要访问Spring MVC控制器中的请求,则应使用标准的HttpServletRequest。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.