到struts上拿的时候乱码了,求大神指导!
6 个解决方案
#1
因为浏览器会自动转码的
#2
1.配置一个filter
2.<a>默认的是get提交,想办法变成post提交,例如用js提交一个表单
2.<a>默认的是get提交,想办法变成post提交,例如用js提交一个表单
#3
没有配置中文过滤器吗
#4
/**
* @see 接受客户端请求的数据(String)
* @param paramName 参数名称
* @return String
* */
public String paramString(String paramName) {
String result = paramStr(paramName);
try {
if ("GET".equalsIgnoreCase(getRequest().getMethod())) {
if (getRequest().getHeader("User-Agent").toLowerCase().indexOf("MSIE".toLowerCase()) != -1) {
result = new String(result.getBytes("ISO-8859-1"), "GBK");
} else {
result = new String(result.getBytes("ISO-8859-1"), "UTF-8");
}
}
} catch (Exception e) {}
return result;
}
/**
* @see 获得request
* @return HttpServletRequest
* */
public HttpServletRequest getRequest() {
return ServletActionContext.getRequest();
}
// 接收客户端请求的数据
private String paramStr(String paramName) {
return (null != getRequest().getParameter(paramName)) ? getRequest().getParameter(paramName) : "";
}
用最上边这个方法试试,包你没乱码
* @see 接受客户端请求的数据(String)
* @param paramName 参数名称
* @return String
* */
public String paramString(String paramName) {
String result = paramStr(paramName);
try {
if ("GET".equalsIgnoreCase(getRequest().getMethod())) {
if (getRequest().getHeader("User-Agent").toLowerCase().indexOf("MSIE".toLowerCase()) != -1) {
result = new String(result.getBytes("ISO-8859-1"), "GBK");
} else {
result = new String(result.getBytes("ISO-8859-1"), "UTF-8");
}
}
} catch (Exception e) {}
return result;
}
/**
* @see 获得request
* @return HttpServletRequest
* */
public HttpServletRequest getRequest() {
return ServletActionContext.getRequest();
}
// 接收客户端请求的数据
private String paramStr(String paramName) {
return (null != getRequest().getParameter(paramName)) ? getRequest().getParameter(paramName) : "";
}
用最上边这个方法试试,包你没乱码
#5
struts.xml配置文件加上这样一句话
<constant name="strtus.i18n.encoding" value="UTF-8" />
<constant name="strtus.i18n.encoding" value="UTF-8" />
#6
var newPage = window.open("");
newPage.document.write("<form method='post' id='fm' name='fm' action='site\/productAction!findByTypeIdPerPage.action'>");
newPage.document.write("<input type='hidden' name='typeId' value='"+typeId+"'\/>");
newPage.document.write("<input type='hidden' name='typeName' value='"+typeName+"'\/>");
newPage.document.write("<input type='hidden' name='pageSize' value='36'\/>");
newPage.document.write("<\/form>");
newPage.document.fm.submit();
newPage.document.write("<form method='post' id='fm' name='fm' action='site\/productAction!findByTypeIdPerPage.action'>");
newPage.document.write("<input type='hidden' name='typeId' value='"+typeId+"'\/>");
newPage.document.write("<input type='hidden' name='typeName' value='"+typeName+"'\/>");
newPage.document.write("<input type='hidden' name='pageSize' value='36'\/>");
newPage.document.write("<\/form>");
newPage.document.fm.submit();
#1
因为浏览器会自动转码的
#2
1.配置一个filter
2.<a>默认的是get提交,想办法变成post提交,例如用js提交一个表单
2.<a>默认的是get提交,想办法变成post提交,例如用js提交一个表单
#3
没有配置中文过滤器吗
#4
/**
* @see 接受客户端请求的数据(String)
* @param paramName 参数名称
* @return String
* */
public String paramString(String paramName) {
String result = paramStr(paramName);
try {
if ("GET".equalsIgnoreCase(getRequest().getMethod())) {
if (getRequest().getHeader("User-Agent").toLowerCase().indexOf("MSIE".toLowerCase()) != -1) {
result = new String(result.getBytes("ISO-8859-1"), "GBK");
} else {
result = new String(result.getBytes("ISO-8859-1"), "UTF-8");
}
}
} catch (Exception e) {}
return result;
}
/**
* @see 获得request
* @return HttpServletRequest
* */
public HttpServletRequest getRequest() {
return ServletActionContext.getRequest();
}
// 接收客户端请求的数据
private String paramStr(String paramName) {
return (null != getRequest().getParameter(paramName)) ? getRequest().getParameter(paramName) : "";
}
用最上边这个方法试试,包你没乱码
* @see 接受客户端请求的数据(String)
* @param paramName 参数名称
* @return String
* */
public String paramString(String paramName) {
String result = paramStr(paramName);
try {
if ("GET".equalsIgnoreCase(getRequest().getMethod())) {
if (getRequest().getHeader("User-Agent").toLowerCase().indexOf("MSIE".toLowerCase()) != -1) {
result = new String(result.getBytes("ISO-8859-1"), "GBK");
} else {
result = new String(result.getBytes("ISO-8859-1"), "UTF-8");
}
}
} catch (Exception e) {}
return result;
}
/**
* @see 获得request
* @return HttpServletRequest
* */
public HttpServletRequest getRequest() {
return ServletActionContext.getRequest();
}
// 接收客户端请求的数据
private String paramStr(String paramName) {
return (null != getRequest().getParameter(paramName)) ? getRequest().getParameter(paramName) : "";
}
用最上边这个方法试试,包你没乱码
#5
struts.xml配置文件加上这样一句话
<constant name="strtus.i18n.encoding" value="UTF-8" />
<constant name="strtus.i18n.encoding" value="UTF-8" />
#6
var newPage = window.open("");
newPage.document.write("<form method='post' id='fm' name='fm' action='site\/productAction!findByTypeIdPerPage.action'>");
newPage.document.write("<input type='hidden' name='typeId' value='"+typeId+"'\/>");
newPage.document.write("<input type='hidden' name='typeName' value='"+typeName+"'\/>");
newPage.document.write("<input type='hidden' name='pageSize' value='36'\/>");
newPage.document.write("<\/form>");
newPage.document.fm.submit();
newPage.document.write("<form method='post' id='fm' name='fm' action='site\/productAction!findByTypeIdPerPage.action'>");
newPage.document.write("<input type='hidden' name='typeId' value='"+typeId+"'\/>");
newPage.document.write("<input type='hidden' name='typeName' value='"+typeName+"'\/>");
newPage.document.write("<input type='hidden' name='pageSize' value='36'\/>");
newPage.document.write("<\/form>");
newPage.document.fm.submit();