我想用这种方法导出excel文件,但是导出来的文件打开是乱码,请问是什么原因,谢谢了<%@ page contentType="application/msexcel" %> 
<!-- 以上这行设定本网页为excel格式的网页 --> 
<% 
response.setHeader("Content-disposition","inline; filename=test1.xls"); 
//以上这行设定传送到前端浏览器时的档名为test1.xls 
//就是靠这一行,让前端浏览器以为接收到一个excel档 
%> 
<html> 
<head> 
<title>Excel档案呈现方式</title> 
</head> 
<body> 
<table border="1" width="100%"> 
<tr> 
<td>姓名</td><td>身份证字号</td><td>生日</td> 
</tr> 
<tr> 
<td>李</td><td>N111111111</td><td>1900/11/12</td> 
</tr> 
<tr> 
<td>梁</td><td>N222222222</td><td>1923/10/1</td> 
</tr> 
<tr> 
<td>张</td><td>N333333333</td><td>1934/12/18</td> 
</tr> 
</table> 
</body> 
</html> 

解决方案 »

  1.   

    你用的这种方式:你可以试着设一下网页的编码!主要是jsp页的!
    <%page ……>就可以!
      

  2.   

    这种用法很新鲜,帮你测试了下,页面没有出现乱码,可能是你的jsp文件本身编码不一致吧
      

  3.   

    贡献个方法private void setContentType(HttpServletResponse response, String fileName) {
    String surfix=fileName.substring(fileName.lastIndexOf('.')+1);
    if (surfix.equalsIgnoreCase("pdf")) {
    response.setContentType("application/pdf");
    return ;
    }
    if (surfix.equalsIgnoreCase("rar")) {
    response.setContentType("application/rar");
    return ;
    }
    if (surfix.equalsIgnoreCase("zip")) {
    response.setContentType("application/zip");
    return ;
    }
    if (surfix.equalsIgnoreCase("xls")) {
    response.setContentType("application/x-xls");
    return ;
    }
    if (surfix.equalsIgnoreCase("doc")) {
    response.setContentType("application/msword");
    return ;
    }
    if (surfix.equalsIgnoreCase("docx")) {
    response.setContentType("application/vnd.openxmlformats-officedocument.wordprocessingml.document");
    return ;
    }
    if (surfix.equalsIgnoreCase("ppt")) {
    response.setContentType("application/vnd.ms-powerpoint");
    return ;
    }
    if (surfix.equalsIgnoreCase("pptx")) {
    response.setContentType("application/vnd.openxmlformats-officedocument.presentationml.presentation");
    return ;
    }


    }
      

  4.   

    测试了,test1.xls这个不是乱码,jsp倒是乱码,文件的编码格式iso-8859-1的,
      

  5.   

    改下JSP的编码格式,,最好改成UTF-8
      

  6.   

    至少你也得指定一下编码才行啊,page  ,和meta里的
      

  7.   

    <%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
      

  8.   

    <%@ page language="java" pageEncoding="gbk"%>
    <%@ page contentType="application/msexcel" %> 
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <%
        response.setHeader("Content-disposition", "inline; filename=test1.xls");
        //以上这行设定传送到前端浏览器时的档名为test1.xls 
        //就是靠这一行,让前
    %><html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>导出</title>
    </head>
    <body>
    <table border="1" width="100%">
    <tr>
    <td>
    姓名
    </td>
    <td>
    身份证字号
    </td>
    <td>
    生日
    </td>
    </tr>
    <tr>
    <td>

    </td>
    <td>
    N111111111
    </td>
    <td>
    1900/11/12
    </td>
    </tr>
    <tr>
    <td>

    </td>
    <td>
    N222222222
    </td>
    <td>
    1923/10/1
    </td>
    </tr>
    <tr>
    <td>

    </td>
    <td>
    N333333333
    </td>
    <td>
    1934/12/18
    </td>
    </tr>
    </table>
    </body>
    </html>俺也测了一下!你就少了
    <%@ page language="java" pageEncoding="gbk"%>加上就一切正常了