又见乱码!!!

leqixb 2004-12-20 05:26:08
我的WEB中加了一个按钮,是将报表显示为Excel格式,代码为:
<form name='excel' action="../excel.xls" onSubmit="return setContent();" method='post'>
<div style="display:none">
<input name='report' type=text >
</div>
<input type="image" src="/sub/img/Excel2.gif" STYLE='POSITION:ABSOLUTE; RIGHT:20; TOP:5; cursor:"hand"'></input>
</form>
<SCRIPT>
function setContent(){
excel.report.value=document.all.REPORT_CONTENT.outerHTML;
return true;
}
</SCRIPT>


excel.xls文件为:
<%@page contentType="application/vnd.ms-excel;charset=GB2312" %>
<%@page import="utilplus.*"%>
<HTML>
<HEAD>
<META content='text/xls; charset=gb2312' http-equiv=Content-Type>
</HEAD>
<body>
<%
String content = request.getParameter("report");
out.println(content);
%>
</body>
</HTML>



在web.xml中添加了如下设置:
<servlet-mapping>
<servlet-name>jsp</servlet-name>
<url-pattern>*.xls</url-pattern>
</servlet-mapping>
但是点击excel按钮就出现乱码,我该怎么办?谢谢!
...全文
190 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
leqixb 2004-12-23
  • 打赏
  • 举报
回复
?
leqixb 2004-12-23
  • 打赏
  • 举报
回复
将excel.xls文件中的content转码就行了,^_^
leqixb 2004-12-22
  • 打赏
  • 举报
回复
高手请!分数可以加!
fengliu212 2004-12-22
  • 打赏
  • 举报
回复
关注
leqixb 2004-12-21
  • 打赏
  • 举报
回复
这个方法我在页面中有关中文显示的时候用的,可是有关excel中我就不知道该怎么用了,但还是要谢谢你!盼高人指点!
ymm 2004-12-20
  • 打赏
  • 举报
回复
public static String toChinese(String str) {
try{
if(str==null){
return null;
}
else{
str=new String(str.getBytes("ISO8859_1"),"GBK");
return str;
}
}
catch(Exception e){
return null;
}
}

81,091

社区成员

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

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