Spring MVC中的WebRequest和HttpServletRequest [英] WebRequest and HttpServletRequest in Spring MVC

查看:2073
本文介绍了Spring MVC中的WebRequest和HttpServletRequest的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

两者有什么区别?两者都有 getParameter 方法以及 setAttribute 方法,那么两者之间的区别在哪里?

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?

1)哪一种更适合一般使用?

1) Which one is better to use in general?

2)请解释可以使用它们的具体方案。

2) Please explain specific scenarios where they can be used.

推荐答案

WebRequest的javadoc 非常明确:


Web请求的通用接口。 主要用于通用Web请求拦截器,允许他们访问一般请求元数据,而不是实际处理请求。

(强调我的)。

javadoc链接到WebRequestInterceptor,它说:

The javadoc links to WebRequestInterceptor, which says:


一般Web请求拦截的接口。通过构建WebRequest抽象,允许应用于Servlet请求以及Portlet请求环境。

Interface for general web request interception. Allows for being applied to Servlet request as well as Portlet request environments, by building on the WebRequest abstraction.

所以,基本上,除了WebRequestInterceptor之外,你不应该使用WebRequest。他们引入了这个接口,以便能够编写适用于servlet和portlet的拦截器。除此之外,如果你真的需要访问Spring MVC控制器中的请求,你应该使用标准的HttpServletRequest。

So, basically, you should not use WebRequest except in a WebRequestInterceptor. And they introduced this interface in order to be able to write interceptors that apply to servlets and portlets. Other than that, if you really need access to the request in Spring MVC controllers, you should use the standard HttpServletRequest.

这篇关于Spring MVC中的WebRequest和HttpServletRequest的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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