我的环境是
tomcat5.0+mysql5.0+繁体版本(由于台湾客户要繁体)
我的xml
<?xml version="1.0" encoding="big5"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">
<jsp-config>
<jsp-property-group>
<description>Special property group for JSP Configuration JSP example.</description>
<display-name>JSPConfiguration</display-name>
<url-pattern>*.jsp</url-pattern>
<url-pattern>*.html</url-pattern>
<el-ignored>true</el-ignored>
<page-encoding>GBK</page-encoding>
<scripting-invalid>false</scripting-invalid>
</jsp-property-group>
</jsp-config>
</web-app>
我的数据链接这样的:
conn=jdbc:mysql://127.0.0.1/tis?user=root&password=&useUnicode=true&characterEncoding=GBK
然后我页面上接收数据的代码如下<%@ include file ="verify.jsp"%>
<%@ page contentType="text/html; charset=big5" language="java" import="java.sql.*" %>
<%@ page import="java.text.*"%>
<%@ page import="java.util.List,java.util.ArrayList,java.util.Map,java.util.HashMap"%>
<%
request.setCharacterEncoding("GBK");
response.setContentType("text/html;charset=GBK");
%>
这个是开头的,
收到表单过来的数据
String note=new String(request.getParameter("note").getBytes("ISO_8859_1"),"big5");
用这种方法的之前一切OK,然后放到我朋友服务器上几天后就出现添加的数据是???的现象
我自己主观认为我本地机子OK的,可能是我朋友服务器上的问题。
但是一切并非尽人所料,张于,我自己本地机子上也出现了这种问题。
也算不出是什么原因导致,好像是突然之间的。
tomcat5.0+mysql5.0+繁体版本(由于台湾客户要繁体)
我的xml
<?xml version="1.0" encoding="big5"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">
<jsp-config>
<jsp-property-group>
<description>Special property group for JSP Configuration JSP example.</description>
<display-name>JSPConfiguration</display-name>
<url-pattern>*.jsp</url-pattern>
<url-pattern>*.html</url-pattern>
<el-ignored>true</el-ignored>
<page-encoding>GBK</page-encoding>
<scripting-invalid>false</scripting-invalid>
</jsp-property-group>
</jsp-config>
</web-app>
我的数据链接这样的:
conn=jdbc:mysql://127.0.0.1/tis?user=root&password=&useUnicode=true&characterEncoding=GBK
然后我页面上接收数据的代码如下<%@ include file ="verify.jsp"%>
<%@ page contentType="text/html; charset=big5" language="java" import="java.sql.*" %>
<%@ page import="java.text.*"%>
<%@ page import="java.util.List,java.util.ArrayList,java.util.Map,java.util.HashMap"%>
<%
request.setCharacterEncoding("GBK");
response.setContentType("text/html;charset=GBK");
%>
这个是开头的,
收到表单过来的数据
String note=new String(request.getParameter("note").getBytes("ISO_8859_1"),"big5");
用这种方法的之前一切OK,然后放到我朋友服务器上几天后就出现添加的数据是???的现象
我自己主观认为我本地机子OK的,可能是我朋友服务器上的问题。
但是一切并非尽人所料,张于,我自己本地机子上也出现了这种问题。
也算不出是什么原因导致,好像是突然之间的。
解决方案 »
- 缺少对象
- 在线等,急!以下的语句,每一句都分别显示“需要标识符”;“非法的类型开始 ”
- com.microsoft.sqlserver.jdbc.SQLServerException: 到主机 的 TCP/IP 连接失败。
- 使用jboss運行,struts遇到一個奇怪問題,請大家幫忙
- 关于在Tomcat部署war文件外网访问问题
- 请教一下,我写的代码怎么报告空指针指向错误?请高手指教
- 急求jsp图片上传代码!
- JSP连接MSSQL2000有问题的朋友,看看此贴,或许让你少走些弯路
- 请问下document.forms[0].action=reportToExcel+"excel";是什么意思啊,forms[0]我找不到这个form啊
- DOM手册?
- 面向对象的疑问,看看高手怎么解决这类问题的
- jsp连接数据库出错
我估计多半就是你转码的问题~
你每次都转 从数据库里取出正常的汉字页转了一下 然后显示 自然就便乱码???了
看看代码你转码的那块~
我测试了个最简单的数据<%
String type=Tochar.getStr(request.getParameter("type"));
if(type.equals("add")){
int fatherid=Integer.parseInt(Tochar.getStr(request.getParameter("fatherid")));
int grade=Integer.parseInt(Tochar.getStr(request.getParameter("grade")));
String name=new String(request.getParameter("name").getBytes("ISO_8859_1"),"big5");
String name1=request.getParameter("name");
String name2=Tochar.getStr(request.getParameter("name"));
String name3=new String(request.getParameter("name").getBytes("ISO_8859_1"),"gbk");
%>
<%=name%><br>
<%=name1%><br>
<%=name2%><br>
<%=name3%><br>
<%}%>结果是:
????
穝竤舱
????
????说明和表单得到数据有关系,和数据库没什么大关系。但事实上我在之前,至少前天还是好好的,昨天忙点别的事,我不清楚。之前也是查了好久才查出办法了,不知道为什么现在这样了。大家帮帮我啦
顶!!
<%@ page contentType="text/html; charset=GB2312" %>在xml中加上
<?xml version="1.0" encoding="UTF-8"?>
之前对的,如果现在要改,麻烦了,要改动地方太多了。
如果有一次就能把代码全部弄得没用的办法,那理论上应该存在着一次能把代码修好的办法 我希望把这个修好方法找到来,可以的话,可以找到怎么破坏的方法就更好了,以后可以注意了。
package net.action;
import java.util.*;
import java.sql.*;
import java.io.*;
/**
* 系统名: 字符转换
* 功 能: 字符转换
* 作 者: 胡文虎
*/
public class Tochar
{
public static String getStr(String str) {
try{
String temp_p=str;
byte[] temp_t=temp_p.getBytes("ISO8859_1");
String temp=new String(temp_t); return temp;
}
catch(Exception e){
} //return "";
if(str == null)
return "";
else
return str;
}
}
public class Tochar
{
public static String getStr(String str)
{
try
{
String temp_p = str; Encoding encoder = Encoding.GetEncoding("big5");
byte[] temp_t = encoder.GetBytes(temp_p);
char[] tempchar = new char[encoder.GetCharCount(temp_t, 0, temp_t.Length)];
encoder.GetChars(temp_t, 0, temp_t.Length, tempchar, 0);
string temp = new string(tempchar);
return temp;
}
catch (Exception e)
{
} //return "";
if (str == null)
return "";
else
return str;
}
}
还有一个转换代码 string unicodeString = "This string contains the unicode character Pi(\u03a0)"; Encoding ascii = Encoding.ASCII;
Encoding unicode = Encoding.Unicode;
byte[] unicodeBytes = unicode.GetBytes(unicodeString);
byte[] asciiBytes = Encoding.Convert(unicode, ascii, unicodeBytes);
char[] asciiChars = new char[ascii.GetCharCount(asciiBytes, 0, asciiBytes.Length)];
ascii.GetChars(asciiBytes, 0, asciiBytes.Length, asciiChars, 0);
string asciiString = new string(asciiChars);
Response.Write( unicodeString);
Response.Write( asciiString);你自己试一下吧