String convEncodeing(String str, String enc1, String enc2)
{
try
{
if(enc1 == null)
en
String convEncodeing(String str, String enc1, String enc2)
{
try
{
if(enc1 == null)
enc1 = new String("8859_1");
if(enc1.equalsIgnoreCase(enc2))
{
return str;
} else
{
String strEncodeing = new String(str.getBytes(enc1), enc2);
return strEncodeing;
}
}
catch(Exception e)
{
log("Convert '" + str + "' Encodeing from " + enc1 + " to " + enc2 + " error:" + e);
}
return str;
}
void putParaInDataBean(HttpServletRequest request, DefaultDataBean dBean)
{
Enumeration names = null;
int i = 0;
String charEncodeing = request.getCharacterEncoding();
String strQuery = request.getQueryString();
if(strQuery == null)
strQuery = "";
dBean.putAttribute("QueryString", strQuery);
log("Put QueryString: " + strQuery);
for(names = request.getParameterNames(); names.hasMoreElements();)
{
String name = (String)names.nextElement();
String vals[] = request.getParameterValues(name);
for(i = 0; i < vals.length; i++)
{
vals[i] = convEncodeing(vals[i], charEncodeing, m_defEncodeing);
dBean.putAttribute(name, vals[i], i);
System.out.println(name + ":" + vals[i]);
}
}
DataInputStream in = null;
String strValue = null;
try
{
in = new DataInputStream(request.getInputStream());
strValue = in.readUTF();
}
catch(IOException e)
{
log("Put InputStream error:" + e.getMessage());
}
if(strValue == null)
strValue = "";
dBean.putAttribute("InputStream", strValue);
log("Put InputStream: " + strValue);
Cookie cookie[] = request.getCookies();
if(cookie == null)
log("Cookie empty");
else
for(i = 0; i < cookie.length; i++)
{
String val = convEncodeing(cookie[i].getValue(), charEncodeing, m_defEncodeing);
dBean.putAttribute(cookie[i].getName(), val);
}
String name;
Object obj;
for(names = request.getSession().getAttributeNames(); names.hasMoreElements(); dBean.putAttribute(name, obj))
{
name = (String)names.nextElement();
obj = request.getSession().getAttribute(name);
if(obj instanceof String)
obj = convEncodeing((String)obj, charEncodeing, m_defEncodeing);
}
}
这段代码里为什么
putParaInDataBean函数里要进行编码转换,而且为什么val[i]要转换而name 不要转换呢?
展开
全部