HttpServletRequest接口和HttpServletResponse接口是继承ServletRequest和ServletResponse接口,是他们的子接口,但是我们在程序中进程看到ServletRequest强制转换成HttpServletRequest类型,这
是因为,虽然ServletRequest是HttpServletRequest的父接口,但是他们的实现类是有web容器来实现的,虽然不同的容器实现的方式不同,但是多态的情况下,子类可以强制转换成父类类型,这是可以的。
例如:
HttpServletRequest httpServletRequest = (HttpServletRequest) request;
String method = httpServletRequest.getMethod();