servlet的中文问题

bigchen 2000-03-04 12:56:00
加精
httpservletrequest的getparameter()不支持中文
...全文
598 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
yourice 2000-09-06
  • 打赏
  • 举报
回复
use this class:

package lib.utils;
import java.io.UnsupportedEncodingException;

public class myText
{
public static String getDBString(String uni)
{
String result = null;
try {
result = new String(uni.getBytes("8859_1"));
} catch(UnsupportedEncodingException e) {
System.out.println("JVM doesn't support encoding 8859_1");
} catch(Exception e) {
System.out.println(e);
}
return result;
}

public static String getDBString(String uni, String defresult)
{
String result = null;
try {
result = new String(uni.getBytes("8859_1"));
} catch(UnsupportedEncodingException e) {
System.out.println("JVM doesn't support encoding 8859_1");
result = defresult;
} catch(Exception e) {
System.out.println(e);
result = defresult;
}
return result;
}

public static String getParamString(String uni)
{
String result = null;
try {
result = new String(uni.getBytes("8859_1"),"GBK");
} catch(UnsupportedEncodingException e) {
System.out.println("JVM doesn't support encoding 8859_1 or GBK");
} catch(Exception e) {
System.out.println(e);
}
return result;
}
}
lowhand 2000-08-10
  • 打赏
  • 举报
回复
hongfei讲的对
hongfei 2000-03-28
  • 打赏
  • 举报
回复
Now I have a way of solute chinese problem in java
(include jdbc-odbc bridge but as if only fit jdk 1.1.* and 1.0.*)
the way is using encoding way.

the "iso-8859-1" encoding is the most wide english encoding solution
supposing the chinese data is readed from file or database in String "sChData",
you must deal with the following code
" byte[] ch_byte = sChData.getBytes("iso-8859-1");
//here we force java vm to read chinese data in a english way
sChData = new String(ch_byte);
//and here we force to turn into unicode data",

in addition, when data writed to file or db , and use the following code
" byte[] ch_byte = sChData.getBytes();
//here we divide the string into byte array
sChData = new String(ch_byte,"iso-8859-1");
//and here we force to turn to the english way from
// the unicode byte array"

if you want to send data among threads, please use Reader/writer
in jdk 1.1.* or jdk 1.2.* to send the unicode data which are dealt
with the first way;

the way fit in all java editions except for jdbc in jdk1.2
(it is only now I have not solutions.)

My code is here (use chinese params of sql to
read the chinese data from database):

(environment :visualage for java 2.0)

import java.sql.*;
/**
* This type was created in VisualAge.
*/
class MyTest {
/**
* This method was created in VisualAge.
* @param args java.lang.String[]
*/
public static void main(String args[]) {
Connection con = null;
Statement myState = null;
ResultSet myRSet = null;
String url, sName;
try {
url = "jdbc:odbc:paper";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection(url, "", "");
myState = con.createStatement();
String sql = "select paperName from paper where author = \'张三\'";
byte[] ch_Byte = sql.getBytes();
sql = new String(ch_Byte,"iso-8859-1");
myRSet = myState.executeQuery(sql);
while (myRSet.next()) {
sName = myRSet.getString("paperName");
ch_Byte = sName.getBytes("iso-8859-1");
sName = new String(ch_Byte);
System.out.println("Name: " + sName);
}
} catch (Exception e) {
System.out.println("error: " + e.toString());
}
}
}
errorzhl 2000-03-26
  • 打赏
  • 举报
回复
String nickname=request.getParameter("nickname");
BufferedReader reader = new BufferedReader(new InputStreamReader(new StringBufferInputStream(nickname), "GBK"));
nickname = reader.readLine();
chenjp 2000-03-17
  • 打赏
  • 举报
回复
不知道你是什么环境。根据我的经验,
主要与JVM的Local Language设定有关。
keven 2000-03-12
  • 打赏
  • 举报
回复
servlet不支持中文的问题我也曾碰到,我的操作环境是WINDOWS NT4.0,将系统时区及语言代码改为美国英语,中文问题就解决了。您可以试试。
Rich 2000-03-09
  • 打赏
  • 举报
回复
如果是Post过来的数据,应该没问题,如果是Get方法的中文就有问题,有的时候读不出来.
解决方法就是不用 get方法传数据.
ahfei 2000-03-06
  • 打赏
  • 举报
回复
支持!不过必须在英文区域下编译你的servlet
土豆 2000-03-05
  • 打赏
  • 举报
回复
bigchen 2000-03-04
  • 打赏
  • 举报
回复
我现在只能用getreader(),然后在解码,实在很繁,有什么简单的方法吗?
radish 2000-03-04
  • 打赏
  • 举报
回复
真的吗?会不会是要解码呢?

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧