请教jsp+oracle中文乱码问题,请高手帮忙!

VIEKYXIANG 2009-03-10 05:55:10
问题是如果单纯的在JDBC里面直接用insert into语句可以直接插入到数据库,不会显示乱码,而在jsp页面写入数据库的时候就出现了乱码 很多???¥这些符号,
请问怎么回事????

<%@ page language="java" pageEncoding="UTF-8" contentType="text/html;charset=UTF-8"%>

用GBK也一样 我的数据库是oracle 10g
...全文
152 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
babe0555 2009-03-11
  • 打赏
  • 举报
回复
接受数据的时候没有进行字符集编码。加上字符集过滤器一般就ok了。
VIEKYXIANG 2009-03-10
  • 打赏
  • 举报
回复
ACTION里面
UserForm userForm = (UserForm) form;
Test test = new Test();
test.setUsername(userForm.getUsername());
test.setPassword(userForm.getPassword());

我增加了SetCharacterEncodingFilter.java 也没有用

后来加了GBKString.java也没有用

public class GBKString implements UserType {
public GBKString() {
super();
}

public int[] sqlTypes() {
return new int[] { OracleTypes.VARCHAR };
}

public Class returnedClass() {
return String.class;
}

public boolean equals(Object x, Object y) throws HibernateException {
return (x == y) || (x != null && y != null && (x.equals(y)));
}

public Object nullSafeGet(ResultSet rs, String[] names, Object owner) throws HibernateException,
SQLException {
String val = rs.getString(names[0]);
if (null == val) {
return null;
} else {
try {
val = new String(val.getBytes("iso-8859-1"), "UTF-8");
} catch (UnsupportedEncodingException e) {
throw new HibernateException(e.getMessage());
}
return val;
}
}

public void nullSafeSet(PreparedStatement st, Object value, int index) throws HibernateException,
SQLException {
if (value == null) {
st.setNull(index, OracleTypes.VARCHAR);
} else {
String val = (String)value;
try {
val = new String(val.getBytes("UTF-8"), "iso-8859-1");
} catch (UnsupportedEncodingException e) {
throw new HibernateException(e.getMessage());
}
st.setObject(index, val, OracleTypes.VARCHAR);
}
}

public Object deepCopy(Object value) throws HibernateException {
if (value == null)
return null;
return new String((String) value);
}

public boolean isMutable() {
return false;
}

public Object assemble(Serializable arg0, Object arg1) throws HibernateException {
// TODO Auto-generated method stub
return null;
}

public Serializable disassemble(Object arg0) throws HibernateException {
// TODO Auto-generated method stub
return null;
}

public int hashCode(Object arg0) throws HibernateException {
return HashCodeBuilder.reflectionHashCode(this);
}

public Object replace(Object arg0, Object arg1, Object arg2) throws HibernateException {
// TODO Auto-generated method stub
return null;
}

}
VIEKYXIANG 2009-03-10
  • 打赏
  • 举报
回复
ACTION里面
UserForm userForm = (UserForm) form;
Test test = new Test();
test.setUsername(userForm.getUsername());
test.setPassword(userForm.getPassword());

我增加了SetCharacterEncodingFilter.java 也没有用

后来加了GBKString.java也没有用

public class GBKString implements UserType {
public GBKString() {
super();
}

public int[] sqlTypes() {
return new int[] { OracleTypes.VARCHAR };
}

public Class returnedClass() {
return String.class;
}

public boolean equals(Object x, Object y) throws HibernateException {
return (x == y) || (x != null && y != null && (x.equals(y)));
}

public Object nullSafeGet(ResultSet rs, String[] names, Object owner) throws HibernateException,
SQLException {
String val = rs.getString(names[0]);
if (null == val) {
return null;
} else {
try {
val = new String(val.getBytes("iso-8859-1"), "UTF-8");
} catch (UnsupportedEncodingException e) {
throw new HibernateException(e.getMessage());
}
return val;
}
}

public void nullSafeSet(PreparedStatement st, Object value, int index) throws HibernateException,
SQLException {
if (value == null) {
st.setNull(index, OracleTypes.VARCHAR);
} else {
String val = (String)value;
try {
val = new String(val.getBytes("UTF-8"), "iso-8859-1");
} catch (UnsupportedEncodingException e) {
throw new HibernateException(e.getMessage());
}
st.setObject(index, val, OracleTypes.VARCHAR);
}
}

public Object deepCopy(Object value) throws HibernateException {
if (value == null)
return null;
return new String((String) value);
}

public boolean isMutable() {
return false;
}

public Object assemble(Serializable arg0, Object arg1) throws HibernateException {
// TODO Auto-generated method stub
return null;
}

public Serializable disassemble(Object arg0) throws HibernateException {
// TODO Auto-generated method stub
return null;
}

public int hashCode(Object arg0) throws HibernateException {
return HashCodeBuilder.reflectionHashCode(this);
}

public Object replace(Object arg0, Object arg1, Object arg2) throws HibernateException {
// TODO Auto-generated method stub
return null;
}

}
Defonds 2009-03-10
  • 打赏
  • 举报
回复
楼主在数据处理的关键部位用System.out.println()/out.println()等方法把数据打印一下,看看问题出在哪里
这样解决起来也有个针对性
kingshigang 2009-03-10
  • 打赏
  • 举报
回复
能不能把你的代码关键的部位拿出来看看

81,092

社区成员

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

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