package com.linying.util;
import javax.servlet.http.HttpServletRequest;
/**
* 字符转换工具,为解决Ajax乱码问题
* @author Ying-er
* @since 2010-5-15 下午03:37:02
* @version 1.00 Ying-er 创建 2010-5-15 下午03:37:02
*/
public final class StringFormatUtil {
/**
* 工具类,禁止实例化
*/
private StringFormatUtil() {
}
/**
* 字符串编码过渡
* @param paramName
* @param request
* @return
*/
public static String getDecodeParamFromReq(String paramName,
HttpServletRequest request) {
String retval = request.getParameter(paramName);
if(retval==null){
return null;
}
try {
/**
* 中间用ISO-8859-1过渡
*/
byte[] b = retval.getBytes("8859_1");
/**
* 转换成GB2312字符
*/
retval = new String(b, "GB2312");
} catch (Exception e) {
e.printStackTrace();
}
return retval;
}
/**
* 数字编码过渡
* @param paramName
* @param request
* @return
*/
public static int getDecodeIntParamFromReq(String paramName,
HttpServletRequest request) {
String strParam = getDecodeParamFromReq(paramName,request);
int intParam;
if (strParam == null) {
intParam = 0;
} else {
Integer tmp = Integer.parseInt(strParam);
intParam = tmp.intValue();
}
return intParam;
}
}
posted on 2010-05-29 10:24
Ying-er 阅读(323)
评论(0) 编辑 收藏 所属分类:
.Net