Tiny
Tiny

Reputation: 27899

How to remove HttpServletRequest parameters (in JSP)?

How can an HttpServletRequest parameter (especially in JSP) be unset or removed (like in PHP using the unset($_POST['index']) function)? I have tried the following.

Map requestMap=request.getParameterMap();
requestMap.remove("index");

but it says

No modifications are allowed to a locked ParameterMap

Is there a way to unset request parameters?

Upvotes: 0

Views: 5664

Answers (2)

Subin Sebastian
Subin Sebastian

Reputation: 10997

What you have to do is write a HttpFilter, write a HttpRequestWrapper of yours(MyRequestWrapper). Override the getParameter method of HttpRequestWrapper in your MyRequestWrapper such that you don't return parameters(may be always return null).

Within filter code, you should override the doFilter method and create a new MyRequestWrapper from ServletRequest Object, then do chanin.doFilter(myRequestWrapper, response)

Upvotes: 1

Stephen C
Stephen C

Reputation: 719229

Is there a way to unset request parameters?

AFAIK, not within the JSP itself (or any Servlet for that matter).

But you could write a Filter that wrapped the current Request in a way that replaces the parameter map.

Upvotes: 3

Related Questions