Servlet1.java
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;public class Servlet1 extends HttpServlet {
    static final private String CONTENT_TYPE = "application/msword";    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType(CONTENT_TYPE);
        OutputStream out = response.getOutputStream();
        FileInputStream fis = new FileInputStream("c:\\本人.doc");
        int b = fis.read();
        while(b!=-1){
            out.write(b);
            b = fis.
            read();        }
        fis.close();
    }
    protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws javax.servlet.ServletException, java.io.IOException {
        doGet(req,resp);
    }
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws javax.servlet.ServletException, java.io.IOException {
        doGet(req,resp);
    }
}jsp1.jsp
<%@ page contentType="application/msword"%>  
<HTML>
<HEAD>
</HEAD>
<BODY>
<imag src="Servlet1" border="0">
</BODY>
</HTML>假如运行jsp1.jsp,那么就出现下载提示框,我不想要这种提示,我期望一调用就显示文档,怎么做呀?

解决方案 »

  1.   

    直接在jsp文件中调用一个doc的路径就可以了
    e.g.<a href="1.doc">
    文件头上加:<%@ page  contentType="application/msword"%>  
    tomcat\conf\web.xml里:
    <mime-mapping>
            <extension>doc</extension>
            <mime-type>application/msword</mime-type>
        </mime-mapping>
      

  2.   

    zxhong(红透半边天) 说的没有错误
      

  3.   

    to zxhong(红头半边天):
       我的word文档是在数据库里取出来的。而且没有命名,只是二进制流,到时候我只想通过调用Servlet1来显示。怎么做呀?
      

  4.   

    BufferedOutputStream output = null; setResponse(responseRef);
    setNameForDownload(nameForDownloadRef); HttpServletResponse response = getResponse();

    try
            {
    byte[] buffer = new byte[fileContentRef.length()];
    buffer = (fileContentRef.toString()).getBytes();
                output = new BufferedOutputStream(response.getOutputStream());
                response.setContentType("application/msword");
                response.setHeader("Content-Disposition", "attachment; filename=youfilename);

    output.write(buffer,0,buffer.length);
    output.flush();        }
            catch(IOException ex)
            {
    System.out.println(ex);
            }
            finally
            {
                try
                {
                    output.close();
                }
                catch(IOException ioexception1)
    {
    }
            }
      

  5.   

    to zxhong(红透半边天) ,一般调用word后,虽然不能保存在服务器上,但是如何使IE显示WORD时不能让客户修改关注