针对displaytag插件出现了分页带中文参数值的时候乱码,下载displaytag源码包,找到该类修改代码
DefaultRequestHelper.java
/**
* @see org.displaytag.util.RequestHelper#getParameterMap()
*/
public Map getParameterMap()
{
Map map = new HashMap();
// get the parameters names
Enumeration parametersName = this.request.getParameterNames();
while (parametersName.hasMoreElements())
{
// ... get the value
String paramName = (String) parametersName.nextElement();
request.getParameter(paramName);
// put key/value in the map
String pName="";
String[] originalValues = (String[]) ObjectUtils.defaultIfNull(
this.request.getParameterValues(paramName),
new String[0]);
try {
if(originalValues[0]!=null){
if(isContainChinese(originalValues[0])){
pName=originalValues[0];
}else{
pName=new String(originalValues[0].getBytes("ISO-8859-1"),"UTF-8");
}
}
} catch (UnsupportedEncodingException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
// String[] values = new String[originalValues.length];
//
// for (int i = 0; i < values.length; i++)
// {
try
{
pName = URLEncoder.encode(StringUtils.defaultString(pName), StringUtils
.defaultString(response.getCharacterEncoding(), "UTF8")); //$NON-NLS-1$
}
catch (UnsupportedEncodingException e)
{
throw new UnhandledException(e);
}
// }
map.put(paramName, pName);
}
// return the Map
return map;
}
public boolean isContainChinese(String str) {
Pattern p = Pattern.compile("[\u4e00-\u9fa5]");
Matcher m = p.matcher(str);
if (m.find()) {
return true;
}
return false;
}