什么从表单里提交的中文数据都变成了"?"

ghost9x 2003-08-20 10:23:32
<%@page language="java" import="java.sql.*"
contentType="text/html;charset=gb2312"%>
我再jsp页面里有上面的语句,可为什么读到的数据还是“?”呢?

请教大家怎么进行转换?需要配置tomcat或java控制台吗?
...全文
49 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
seaman0916 2003-08-20
  • 打赏
  • 举报
回复
在显示前先转化一下!

<jsp:useBean id="chage" scope="session" class="beans.ISOtoGB2312"/>
//调用JavaBean

String result=chage.getConvert(request.getParameter("name")); //转化!

试试吧!
seaman0916 2003-08-20
  • 打赏
  • 举报
回复
给你一个javabean

package beans ;
public class ISOtoGB2312
{
public String getConvert(String str)
{
try
{
byte[] byteStr=str.getBytes("ISO-8859-1");
return new String(byteStr,"gb2312");
}
catch(Exception e)
{
return str;
}
}
}

试试吧!
luckybeggar 2003-08-20
  • 打赏
  • 举报
回复
request.setCharacterEncoding("GBK");
在取出参数之前加上上面的语句
ghost9x 2003-08-20
  • 打赏
  • 举报
回复
加了request.setCharacterEncoding("GB2312"); 后调试出现这样的话:

Error #: 300 : method getCharacterEncoding(java.lang.String) not found in interface javax.servlet.http.HttpServletRequest at line 13
pnileotgx 2003-08-20
  • 打赏
  • 举报
回复
对了!字符编码问题是和平台有关的!尤其进行数据库操作时!读出的字符穿 要进行编码转换!
monbit 2003-08-20
  • 打赏
  • 举报
回复
String result = new String(你网页上得到的字符串.getBytes("iso-8859-1"),"gb2312");
另外,注意try....catch一下,呵呵
这个result就不会是乱码了
pzl686 2003-08-20
  • 打赏
  • 举报
回复
在第一次取出参数之前加上request.setCharacterEncoding("GB2312");
ghost9x 2003-08-20
  • 打赏
  • 举报
回复
谢谢。好麻烦,汗。。

81,091

社区成员

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

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