在页面中读取指定的doc文件然后在IE中打开?? 比如有个test.doc放在本类目录下,然后我另一个jsp页面需要打开后就显示这个test.doc中的内容,方便我只要改了doc就可以在那个jsp页面中显示。contentType="application/msword"只是把当前页面中的内容在ie中用word打开而不是把指定文件去打开。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <%@ page contentType="application/msword;charset=gb2312"%><%@ page import="java.io.*"%><html><head><title></title></head><body><% String path=request.getRealPath("");//取得当前目录的路径 FileReader fr=new FileReader(path + "\\t.doc"); BufferedReader br=new BufferedReader(fr); String Line=br.readLine();//从文件读取一行字符串 //判断读取到的字符串是否不为空 while(Line!=null){ out.println(Line + "<br>");//输出从文件中读取的数据 Line=br.readLine();//从文件中继续读取一行数据 } br.close();//关闭BufferedReader对象 fr.close();//关闭文件%></body></html>-----------------------就是这样子访问我的t.doc然后在浏览器中打开该文件以word的形式。不过中文多是乱码或问号?请问怎么显示word中的正确内容,当然还包括图片文字等超连接,在word内部的 <%@ include file="taglibs.jsp" %><%@page import="java.util.*"%><%@page import="java.io.*" %><%@page import="java.net.*" %><% String filename=""; if(request.getParameter("file")!=null){ filename=request.getParameter("file"); } response.setContentType("application/msword"); response.setHeader("Content-Disposition","attachment;filename="+filename); BufferedInputStream bis=null; BufferedOutputStream bos=null; try{ bis=new BufferedInputStream(new FileInputStream(getServletContext().getRealPath("download/"+filename))); bos=new BufferedOutputStream(response.getOutputStream()); byte[] buff=new byte[1028]; int bytesRead; while(-1!=(bytesRead=bis.read(buff,0,buff.length))){ bos.write(buff,0,bytesRead); } }catch(final IOException e){ e.printStackTrace(); }finally{ if(bis!=null) bis.close(); if(bos!=null) bos.close(); }%> 求救 急急急 操作系统网络配置,如何把time wait的时间调低一些 如何把百度、谷歌的搜索结果捉取并放进自己的网页中 帮帮我写一个程序 session 问题 高分求助简单问题 getParameter中文乱码问题 中文2000server和中文xp是不是同一种编码?? 两个 javabean 中的类怎么继承?谢谢!马上结帖! 求助,怎么更改json-plugin的返回数据的属性名 关于这个问题 如何实现类似网易相册的功能请高手给予一些指点意见.
<%@ page import="java.io.*"%>
<html>
<head>
<title></title>
</head>
<body>
<%
String path=request.getRealPath("");//取得当前目录的路径
FileReader fr=new FileReader(path + "\\t.doc");
BufferedReader br=new BufferedReader(fr);
String Line=br.readLine();//从文件读取一行字符串
//判断读取到的字符串是否不为空
while(Line!=null){
out.println(Line + "<br>");//输出从文件中读取的数据
Line=br.readLine();//从文件中继续读取一行数据
}
br.close();//关闭BufferedReader对象
fr.close();//关闭文件
%>
</body>
</html>-----------------------
就是这样子访问我的t.doc然后在浏览器中打开该文件以word的形式。
不过中文多是乱码或问号?
请问怎么显示word中的正确内容,当然还包括图片文字等超连接,在word内部的
<%@page import="java.util.*"%>
<%@page import="java.io.*" %>
<%@page import="java.net.*" %>
<%
String filename="";
if(request.getParameter("file")!=null){
filename=request.getParameter("file");
}
response.setContentType("application/msword");
response.setHeader("Content-Disposition","attachment;filename="+filename);
BufferedInputStream bis=null;
BufferedOutputStream bos=null;
try{
bis=new BufferedInputStream(new FileInputStream(getServletContext().getRealPath("download/"+filename)));
bos=new BufferedOutputStream(response.getOutputStream());
byte[] buff=new byte[1028];
int bytesRead;
while(-1!=(bytesRead=bis.read(buff,0,buff.length))){
bos.write(buff,0,bytesRead);
}
}catch(final IOException e){
e.printStackTrace();
}finally{
if(bis!=null)
bis.close();
if(bos!=null)
bos.close();
}
%>