Tim Panton wrote: > > I am trying to use the 'new' filter api to add a parameter to a > request before a servlet is invoked. My first try involved > calling getParameterMap()and doing a put() into it. It seems > that map is locked readonly. So now I'm looking at > HttpRequestWrapper but to use that I think I will have to > emulate the whole parameter behaviour just to add a value. has > anyone done this before, or can point me at an example?
You might be able to do something container-specific - cast the ServletRequest to some container implementation class which gives you access to a setter. I haven't investigated that. The only way I could see, using the API, was to extend HttpServletRequestWrapper and override the parameter methods. If you know that your added parameter name won't ever conflict with any of the original request parameters (or any added during an include or forward), I think it can be fairly straightfoward. If you want to merge values, you have to do a little more work. Here's a version of one of the methods; the others are even more straightforward. public Map getParameterMap() { Map parentMap = super.getParameterMap(); if (parentMap.size() == 0 && mParameters.size() == 0) return Collections.EMPTY_MAP; if (parentMap.size() == 0) return Collections.unmodifiableMap(mParameters); if (mParameters.size() == 0) return parentMap; Map paramMap = new HashMap(parentMap); paramMap.putAll(mParameters); return Collections.unmodifiableMap(paramMap); } Gennis ___________________________________________________________________________ To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff SERVLET-INTEREST". Archives: http://archives.java.sun.com/archives/servlet-interest.html Resources: http://java.sun.com/products/servlet/external-resources.html LISTSERV Help: http://www.lsoft.com/manuals/user/user.html