Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to add to the available parameters of a request (HttpServletRequest)

I want to intercept a request in a filter/servlet and add a few parameters to it. However, the request does not expose a 'setParameter' method and the parameter map when manipulated throws an error saying it is locked. Is there an alternative I can try?

like image 200
Vivek Kodira Avatar asked Oct 10 '08 11:10

Vivek Kodira


People also ask

How do you get the parameters of a httpservletrequest?

Parameters. The HttpServletRequest provides methods for accessing parameters of a request. The type of request determines where the parameters come from. In most implementations, a GET request takes the parameters from the query string, while a POST request takes the parameters from the posted arguments.

What are the different parts of a httpservletrequest?

The HttpServletRequest breaks a request down into parsed elements, such as request URI, query arguments and headers. Various get methods allow you to access different parts of the request. The requestURI deals with the URL sent by the browser. GetRequestURI - /MyWebApplication/personal/info/top.html GetPathInfo - /info/top.html

How do I send HTTP request parameters?

You can send request parameters as part of the URL or as part of the body of an HTTP request. The request.getParameter () is used to get the HTTP request parameters from the request and returns a string.

How do I get the current session in httpservletrequest?

HttpServletRequest interface provides a getSession() method, which returns the current session associated with this request, or if the request does not have a session, creates one. The session object can hold information about a given user, between requests.


1 Answers

Subclass HttpServletRequestWrapper and override the getParameter methods. The description of this class reads:

Provides a convenient implementation of the HttpServletRequest interface that can be subclassed by developers wishing to adapt the request to a Servlet.

In the filter, wrap the request in an instance of your subclass.

like image 143
Bruno De Fraine Avatar answered Sep 29 '22 12:09

Bruno De Fraine