1.首先在struts.xml文件里设置<constant name="struts.i18n.encoding" value="utf-8"/>
2.添加如下拦截器。拦截所有参数带中文的请求
2.添加如下拦截器。拦截所有参数带中文的请求
public String intercept(ActionInvocation invocation) throws Exception {HttpServletRequest request= (HttpServletRequest) invocation.getInvocationContext().get(ServletActionContext.HTTP_REQUEST);if(request.getMethod().equalsIgnoreCase("post"))return invocation.invoke();Map<String, Object> params=invocation.getInvocationContext().getParameters();Set<Entry<String, Object>> entries=params.entrySet();for(Iterator<Entry<String, Object>> itor=entries.iterator();itor.hasNext();){Entry<String, Object> entry=itor.next();if(entry.getValue().getClass()==String[].class){String[] strs=(String[]) entry.getValue();for(int i=0;i<strs.length;i++){strs[i]=new String(strs[i].getBytes("ISO-8859-1"), "utf-8");}}}return invocation.invoke();
}