由于需求需要,,,,像request.setParameters 一样的方法。所以了,,,,,,简单的写了一个实现方法
/**
* 设置Parameters 的值
* @param key
* @param val
*/
public void setParameters(String key,String val){
Map m = getRequest().getParameterMap();
java.lang.reflect.Field lockedField;
try {
lockedField = m.getClass().getDeclaredField("locked");
lockedField.setAccessible(true);
//System.out.println(lockedField.get(m));
lockedField.set(m, false);
//System.out.println(lockedField.get(m));
m.put(key, val);
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
public void doFilter(ServletRequest servletRequest,
ServletResponse servletResponse, FilterChain arg2)
throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) servletRequest;
HttpServletResponse response = (HttpServletResponse) servletResponse;
//StringBuffer buffer=request.getRequestURL();
try {
ParameterRequestWrapper parameterRequestWrapper = new ParameterRequestWrapper(request);
arg2.doFilter(parameterRequestWrapper, servletResponse);
} catch (Exception e) {
log.error(e.getLocalizedMessage(), e);
request.setAttribute("exceptionMsg", e);
request.getRequestDispatcher(errorPage).forward(request, response);
}
}
public class ParameterRequestWrapper extends HttpServletRequestWrapper {
public ParameterRequestWrapper(HttpServletRequest request) {
super(request);
}
public String getParameter(String name) {
String v = super.getParameter(name);
if(v == null){
v = (String)getParameterMap().get(name);
}
return v;
}
}