Kelvin
Kelvin

Reputation: 376

Is it possible to get the HttpServletRequest object from HttpServlet?

I am writing a subclass of HttpServlet. And I want to have a method in that subclass to get the HttpServletRequest. However, it seems HttpServlet does not provide that method.

Is there any way to get round to it?

public class CustomServlet extends HttpServlet {
   public HttpServletRequest getRequest() {
     ...
   }
}

Upvotes: 1

Views: 858

Answers (1)

Bor Laze
Bor Laze

Reputation: 2506

HttpServletRequest is a parameter of methods like doGet(), doPost() etc - how do you think to get it from class?

There is no way to do what you want; you can only override some methods and get HttpServletRequest inside them.

Upvotes: 2

Related Questions