看了些资料,终于实现了。
类1:MyRequestWrapper
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
public class MyRequestWrapper extends HttpServletRequestWrapper {
private Map pattributes = new HashMap();
public MyRequestWrapper(HttpServletRequest arg0) {
super(arg0);
this.pattributes.putAll(getParameterMap());
}
public String getParameter(String name) {
Object v = pattributes.get(name);
if (v == null)
return null;
else
return v.toString();
}
public void setParameter(String name, String value) {
this.pattributes.put(name, value);
}
}
类2:Filter
。。。
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException,
ServletException {
MyRequestWrapper request = new MyRequestWrapper((HttpServletRequest) req);
encoding = filterConfig.getInitParameter("encoding");
request.setCharacterEncoding(encoding);
chain.doFilter(request, res);
}
。。。
往HttpServletRequest中增加一个parameter
((MyRequestWrapper) request).setParameter("PNAME", "PVALUE");
从HttpServletRequest中删除一个parameter
public void removeParameter(String name)
{
this.pattributes.remove(name);
}