在这儿你使用"response.sendRedirect(s)",即从本页面重定向到另一
页面打开excel,哪在本页面设置
<%@ page contentType="application/vnd.ms-excel;charset=gb2312"%>
由什么用呢?
为方便,你干脆这样做:
<%@ page contentType="text/html;charset=gb2312" %>
<a href="http://10.159.18.13:9090/test/card092001.xls">文件</a>
点击链接就在IE中打开excel文件。

解决方案 »

  1.   

    针对jsp和servlet:
    解决办法:
    第一:
    在jsp页面加入:
    <%@ page contentType="text/html; charset=gb2312" %>
    或者在servlet里面
      public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html; charset=gb2312");//这是重要的
    上面的如果在不行就用如下的方法在数据入库前进行调用:
    public static String UnicodeToChinese(String s){
      try{
         if(s==null||s.equals("")) return "";
         String newstring=null;
         newstring=new String(s.getBytes("ISO8859_1"),"gb2312");
         return newstring;
        }
      catch(UnsupportedEncodingException e)
      {
      return s;
      }
      }public static String ChineseToUnicode(String s){
      try{
      if(s==null||s.equals("")) return "";
      String newstring=null;
      newstring=new String(s.getBytes("gb2312"),"ISO8859_1");
       return newstring;
      }
      catch(UnsupportedEncodingException e)
      {
      return s;
     }
      }3:)解决weblogic/webshpere中文问题:
    在web.xml文件中需要配置中文环境。r如下:
    <context-param>
      <param-name>weblogic.httpd.inputCharset./*</param-name>
      <param-value>GB2312</param-value>
    </context-param>
      

  2.   

    你在jakarta-tomcat-4.0\conf的web.xml文件中加入
      <mime-mapping>
        <extension>xls</extension>
        <mime-type>application/vnd.ms-excel</mime-type>
      </mime-mapping>
    就可以顯示excel文件
      

  3.   

    假设你使用的ODBC驱动是:Microsoft ODBC Driver for Excel
    假设你有一个名为qa.xls的Excel的文件放在c:下,表单名为qas,数据按以下格式存放:
    company   Address        city
    电器公司  浦东路177号    Shanghai
    机械厂    长江路99号     Shanghai 
    旭日集团   湖南路29号    Nanjing为了用jdbc来获取电子数据表格,你必须创建1个新的数据源,具体步骤如下:
    1。点击控制面板
    2。点击管理工具
    3。点击数据源
    4。选择添加按钮
    5。选择Microsoft Excel Driver,然后点击完成
    6。给数据源起名为qa-list,选择工作簿,后点击确定。
    代码如下:(具体自己研究吧)import java.sql.Connection;
    import java.sql.Statement;
    import java.sql.ResultSet;
    import java.sql.DriverManager;public class ExcelReader
    {
       public static void main(String[] args)
        {
            Connection c=null;
            Statement stmnt=null;
            try
            {
              Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
              c=DriverManager.getConnection("jdbc:odbc:qalist","","");
              stmnt=c.createStatement();
              String query="select company from [qas$] where area='shanghai';";
              ResultSet rs=stmnt.executeQuery(query);
              System.out.println("Found the following companynamein china:");
              while(rs.next())
           {
             System.out.println(rs.getString("company"));
            }
     }
    catch(Exception e)
     {
        System.err.println(e);
     }
    finally
    {
      try
     {
       stmnt.close();
       c.close();
     }
      catch(Exception e)
      {
       System.err.println(e);
       }
      }
     }
    }
    (打的好累哦!)