第一页<input name="name">文本框中输入中文处理那页
<%@ page contentType="text/html;charset=gb2312"%> //如果有这一行的话那name输出为??????,如果没有这一行的话那本页的中文又显示不了,是什么原因呢?各位请告诉小弟一下.
<%
String name=request.getParameter("name");
out.println(name);
out.println("中文");
%>
<%@ page contentType="text/html;charset=gb2312"%> //如果有这一行的话那name输出为??????,如果没有这一行的话那本页的中文又显示不了,是什么原因呢?各位请告诉小弟一下.
<%
String name=request.getParameter("name");
out.println(name);
out.println("中文");
%>
request.setCharacterEncoding("GB2312");
String name=request.getParameter("name");
out.println(name);
out.println("中文");
%>
试试
在加了<%@ page contentType="text/html;charset=gb2312"%> 这句话后通知浏览器,要进行gb2312转码
request.setCharacterEncoding("GB2312");具体最好搜索一下,网上有的,应该很全。
在tomcat下,在resin不用!
<head>
<meta http-equiv="content-Type" content="text/html;charset=gb2312">
</head>
把gb2312换换试试
<%@ page contentType="text/html;charset=8859_1"%>
1) 所有的jsp页面指定字符编码方式,如:Charest=gb2312,Charest=UTF-8等等
2) 在应用服务器中的server.xml方件中找到设置服务器端口的行,一般是这样开头:”<Connector port="8080"”,
3) 在找到的行"<Connector"开头的字符串后加上:URIEncoding="UTF-8" ,保存文件
--------------------------------------------------------------------------
jsp页面有乱码解决方法 所有的jsp页面指定字符编码方式,如:Charest=gb2312,Charest=UTF-8等等
<%@ page contentType="text/html; charset=UTF-8">
--------------------------------------------------------------------------
jsp单个中文参数乱码解决方法 用这个转换一下:
<%!String trans(String chi)
{
string result =null;
byte temp[];
temp=chi.getBytes("iso=8859-1");
result= new String(temp);
}
%>
或者直接这样:
<%
request.setCharacterEncoding("UTF-8");
out.println(request.getParameter("参数ID")
%>
--------------------------------------------------------------------------
{
if(s==null){s="";}
try
{
byte[] b=s.getBytes("ISO-8859-1");
s=new String(b);
}
catch(Exception e)
{
s="";}
return s;
}加上这个方法就OK 了
<meta http-equiv="content-Type" content="text/html;charset=utf-8">不知道说的对不对.
肯定ok了
但要注意,这句必须写在request接收参数之前。否则没用!
public String getstring(String s)
{
if(s==null){s="";}
try
{
byte[] b=s.getBytes("ISO-8859-1");
s=new String(b);
}
catch(Exception e)
{
s="";}
return s;
}