如何才能实现,在JSP页面指定位置上,将服务器上指定目录下的word文件里的内容原样(原格式)显示出来啊?
word里有表格和文字。
要求,直接显示,而不通过设置打开或保存对话框。
直接输入像这样的地址:HTTP://路径/test.doc,会弹出对话框让选择打开或保存,所以不要告诉我用这样的方法。
用iframe src='路径/test.doc',我也试过,结果报404错误。

解决方案 »

  1.   

    另外,如果用iframe src='路径/test.doc',也会弹出对话框让选择打开或保存的话,就不要告诉我这种方法了。
      

  2.   

    <%@page contentType="application/msword;charset=GBK" %>
      

  3.   

    servlet读取word输出流到jsp
    jsp头上加
    <%@page contentType="application/msword;charset=GBK" %> 
      

  4.   

    <%@ page contentType="application/msword;charset=gb2312" %><% 
    File f=new File("D:/Tomcat 5.5/webapps/neiwang/txt/telephone.doc");
    FileInputStream fin=new FileInputStream(f);
    OutputStream output=response.getOutputStream();
    byte[] buf=new byte[1024];
    int r=0;
    response.setContentType("application/msword;charset=GB2312");
    while((r=fin.read(buf,0,buf.length))!=-1)
    {
    output.write(buf,0,r);//response.getOutputStream()
    }
    fin.close();
    output.close();
    %>
      

  5.   

    还是这个方便,直接servlet输出
      

  6.   

    我没有做过这种但是考虑到楼主想要保持word文件在jsp显示的数据格式完全一致,我想可不可以利用dsoframer中间件直接在jsp中嵌入word,这样利用读取方式能够显示,不知道可去不可取,还望楼主定夺
      

  7.   

     试过 JSP 转 Word 文件, 在JSP 页面 头标签有的   读取也应该有吧 你找找 
      

  8.   

    这个能否按照原来的格式显示啊?如果word里有表格等元素,还能否现实啊?
    另外我想通过action来实现啊。
      

  9.   

    推荐使用FCKeditor文本编辑程序,功能强大跟微软office软件一样的功能。不知道能不能满足lz的需求。
      

  10.   

    另外问个问题,jsp如何把excel里的数据读出后保存到SqlServer里啊?
    如果用POI来做,需要哪些JAR包啊?那些JAR包要去哪里下载啊?
      

  11.   

    或许应该换个思路,把word文件转为html,调用收费的ms office,免费的openoffice都可以做到这点POI对表格或者图表貌似有兼容问题
      

  12.   

    用微软的dsoframer控件就可以的
      

  13.   

    可以按照原来显示,也可以显示表格。
    通过action也可以输出。
      

  14.   


    像这样的有合并单元格的,如何用POI来读取excel里的数据读出来后,保存到SqlServer啊?
      

  15.   

    纯操作excel的话还是建议用jxl  使用JXL 读取Excel合并单元格方法import java.io.FileInputStream; 
    import java.io.FileNotFoundException; 
    import java.io.IOException; 
    import java.io.InputStream; import jxl.Range; 
    import jxl.Sheet; 
    import jxl.Workbook; 
    import jxl.read.biff.BiffException; public class ReadExcel { 
    public ReadExcel(){ } 
    public void readExcel(String filepath){ 
    try { 
    InputStream is = new FileInputStream(filepath); 
    Workbook wb = Workbook.getWorkbook(is); 
    int sheet_size = wb.getNumberOfSheets(); 
    for(int index = 0; index < sheet_size ; index++){ 
    Sheet sheet = wb.getSheet(index); 
    Range[] ranges = sheet.getMergedCells(); 
        System.out.println("sheet" + index + "包含" + ranges.length + "个区域"); 
        for(Range space:ranges){ 
        System.out.print(space.getTopLeft().getRow()+1+"行,"); 
        System.out.print(space.getTopLeft().getColumn()+1+"列\t"); 
        System.out.print(space.getBottomRight().getRow()+1+"行,"); 
        System.out.print(space.getBottomRight().getColumn()+1+"列\n"); 
        } 

    } catch (FileNotFoundException e) { 
    e.printStackTrace(); 
    } catch (BiffException e) { 
    e.printStackTrace(); 
    } catch (IOException e) { 
    e.printStackTrace();