form提交中有中文,服务器端中文显示乱码,怎么解决在线等
form中提交的某字段需要中文信息,提交后后台现实该字段是乱码,怎么解决
------解决方案--------------------给你的应用 加一个转码 的filter
或者直接
name = request.getParameter( "name ");
String name = new String(name.getBytes( "ISO8859-1 "), "GBK ");
------解决方案--------------------String trans(String chi)
{
String result = null;
byte temp [];
try
{
temp=chi.getBytes( "iso-8859-1 ");
result = new String(temp);
}
catch(Unsupported
EncodingException e)
{
System.out.println (e.toString());
}
return result;
}
加个转换方法 或者按楼上的做
------解决方案--------------------String name =new String(name.getBytes( "iso-8859-1 "), "gb2312 ") ;
------解决方案--------------------JSP页面加
request.setCharacterEncoding( "GBK ");
或
name = request.getParameter( "name ");
String name = new String(name.getBytes( "ISO8859-1 "), "GBK ");
------解决方案--------------------name = request.getParameter( "name ");
String name = new String(name.getBytes( "ISO8859-1 "), "gb2312 ");
------解决方案--------------------在jsp页面最上端加一句
<%@ page contentType= "text/html;charset=UTF-8 " language= "java "%>
------解决方案--------------------LZ的意思是要在URL中显示乱码吗???
如果是,可以这样转换:
.../test.jsp?test= <%=java.net.URLEncoder.encode(test, "UTF-8 ")%>