servlet中如何处理中文为问号的问题

maocoffee 2003-10-29 01:24:45
小弟从jsp页面中调用了一个servlet,入里边放了一点中文字符,然后再通过servlet的一些逻辑处理,再把这些中文符放入session中,再用jsp页显示,但是变成了问号,请问如何转字符呢
...全文
292 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
maocoffee 2003-10-29
  • 打赏
  • 举报
回复
我再把我的问题说一下
我现在的结构是这样的jsp->servlet->jsp
在第一环节中的jsp页里中文是好的
第二环节中的中文我不知道是不是已经变成问号了
第三环节的jsp页里已经是问号了
应该是在servlet->jsp的时候中文字处理有问题,但我不知道是我在servlet中request时就变成了问号,还是我把处理好的文字放入session中在jsp取session中的值时变成的问号
luyuly 2003-10-29
  • 打赏
  • 举报
回复
在需要字符转换的地方调用下面的方法
public class Convert {
public String page2db(String temp) {
String xxx = null;
try {
xxx = new String(temp.getBytes("GB2312"), "ISO8859-1");
} catch (Exception e) {
System.out.println("Page2db convert Error : " + e.getMessage());
}
return xxx;
}

public String db2page(String temp) {
String xxx = null;
try {
xxx = new String(temp.getBytes("ISO8859-1"), "GB2312");
} catch (Exception e) {
System.out.println("Db2page convert Error : " + e.getMessage());
}
return xxx;
}

}
lcz022 2003-10-29
  • 打赏
  • 举报
回复
<%@ page contentType = "text/html;charset=gb2312" %>
String des = new String(src.getBytes("iso8859-1"),"GBK");
就可以了。
kevincom 2003-10-29
  • 打赏
  • 举报
回复
不好意思,上面的回答是另一个贴子,请原谅!
kevincom 2003-10-29
  • 打赏
  • 举报
回复
<%@ page language="java" contentType="text/html" import="com.jspsmart.upload.*,java.net.*"%>
<jsp:useBean id="mySmartUpload" scope="page" class="com.jspsmart.upload.SmartUpload" />
<%

String filepath=URLDecoder.decode(request.getParameter("f_path"));
String strName = URLDecoder.decode(request.getParameter("strName"));
String strShowName = URLDecoder.decode(request.getParameter("strShowName"));

try{// Initialization
mySmartUpload.initialize(pageContext);
// With options
mySmartUpload.setContentDisposition("attachment;");
mySmartUpload.downloadFile(filepath+strName,null,strShowName);
}catch(Exception e){
out.print("文件下载错误,该文件可能不存在!<br>");
out.print("<a href='javascript:history.back();'>返回</a>");
System.err.println("文件下载错误"+e.getMessage());
}
%>
hxzhappy 2003-10-29
  • 打赏
  • 举报
回复
这个是编码问题,你在显示时编码就可以了!

81,091

社区成员

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

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