不知道为什么我怎么改,都不能在文本框或文本区域中提交的汉字正确显示出来。高手帮忙看一下,我pageEncoding="GB2312"试过了,charset="gb2312"也试过了,byte [] x=b.getBytes("IOS8859-1")也试过了,但不是不出来,//Form1.jsp<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head><body>
<form action="1.jsp" metod="get">
<table border=1 bgcolor="#FDDDFF">
<tr>
<td height="31" colspan="2"><textarea cols="100" name="temp" wrap="hard" rows="10">
</textarea></td>
</tr>
<tr>
<td colspan="2"><div align="center">
<input type="submit" value="OK" name="submit"/>
</div></td>
</tr>
<tr>
<td width="357"><div align="center">姓名:
<input type="text" aligh="center" name="user"/>
</div></td>
<td width="350"><div align="center">密码:
<input type="password" alig="center" name="pwd" />
</div></td>
</tr>
</table>
</form></body>
</html>
//1.jsp<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head><body>
<%
String s1=request.getParameter("user");
String s2=request.getParameter("pwd");
String s3=request.getParameter("temp");
if(s1==null ){
s1=null;
}
if(s2==null){
s2=null;
}
if(s3==null){
s3=null;
}
byte [] b=s3.getBytes("ISO-8859-1");
s3=new String(b);
out.println("<br>你的姓名:"+s1);
out.println("<br>你登陆的密码:"+s2);
out.println("<br>文本区域的内容:"+s3);
%>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head><body>
<form action="1.jsp" metod="get">
<table border=1 bgcolor="#FDDDFF">
<tr>
<td height="31" colspan="2"><textarea cols="100" name="temp" wrap="hard" rows="10">
</textarea></td>
</tr>
<tr>
<td colspan="2"><div align="center">
<input type="submit" value="OK" name="submit"/>
</div></td>
</tr>
<tr>
<td width="357"><div align="center">姓名:
<input type="text" aligh="center" name="user"/>
</div></td>
<td width="350"><div align="center">密码:
<input type="password" alig="center" name="pwd" />
</div></td>
</tr>
</table>
</form></body>
</html>
//1.jsp<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head><body>
<%
String s1=request.getParameter("user");
String s2=request.getParameter("pwd");
String s3=request.getParameter("temp");
if(s1==null ){
s1=null;
}
if(s2==null){
s2=null;
}
if(s3==null){
s3=null;
}
byte [] b=s3.getBytes("ISO-8859-1");
s3=new String(b);
out.println("<br>你的姓名:"+s1);
out.println("<br>你登陆的密码:"+s2);
out.println("<br>文本区域的内容:"+s3);
%>
</body>
</html>
s3=new String(b);
用UTF-8试试看,好像编码要一致才行。
s3=new String(b);
试试,不行再用:
s3 = new String(s3.getByte("ISO-8859-1"),"utf-8");
还要设置一下服务器默认的编码格式
而且我也用:
byte [] b=s3.getBytes("ISO-8859-1");
s3=new String(b);
转换了,但还是不行。 不知道为什么
看好了
两个页面
index.jsp<body>
<form action="test2.jsp">
<input type="text" name="username"/>
<input type="submit" value="提交">
</form>
</body>test2.jsp
<%
String name = request.getParameter("username");
name = new String(name.getBytes("ISO-8859-1"),"GB2312");
%>
<body>
<%=name %>
仅此而已
建议你建一个ACTION类,来接收这些数据,然后再转到你需要的页面,ACTION里面应该用到上面一些朋友说的 name = new String(name.getBytes("ISO-8859-1"),"GB2312"); 这个东西~
String username = request.getParameter("username");
byte[] bytes = username.getBytes("iso-8859-1");
String result = new String(bytes, "gb2312");
out.print(result);
%>
用这个可以了,谢谢大家了