jsp中 显示word 和excel 我现在已经把excel和word为格式的两个文件的路径已确认,怎么才能在jsp页面中分别显示word 和excel 应该怎么做。 谢谢了 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 设置页面的mime类型就可以网上很多 我也找了。。 就是不知道jsp界面是怎么找到文件路径的。 并显示出来的。。 望给予答案。。 谢谢饿 1在web.xml中加入: <mime-mapping> <extension>ppt</extension> <mime-type>application/mspowerpoint</mime-type> </mime-mapping> 2在jsp页头引入<%@page contentType="application/msword;charset=gbk"%>这是在浏览器中已word形式打开<%@page contentType="application/vnd.ms-excel;charset=gbk"%>这是以excel ....是不是和mime相关的,不清楚 我想问一下 jsp是怎么找到路径显示excel和word的 我想问一下 jsp是怎么找到路径显示excel和word的 你在JSP里 加<%response.setContextType("application/vnd.ms-excel");%> 看行不? 直接用个servlet,然后得到文件流,用servletOutputStream输出,输出之前,setContentType("")对应word或者excel的mime类型,如FileInputStream is=new FileInputStream(new File("文件路径"));response.setContentType("正确的mime类型");byte[] b=new byte[is.available()];is.read(b);response.getOutputStream().write(b);这样就输出了 链接的路径会写吧。<a href="./word.doc">open the word</a>在web.xml里面加上下面两句: <mime-mapping> <extension>doc</extension> <mime-type>application/vnd.ms-word</mime-type> </mime-mapping> <mime-mapping> <extension>xls</extension> <mime-type>application/vnd.ms-excel</mime-type></mime-mapping> <% response.setContentType("application/vnd.ms-excel"); String xlsFile = this.getClass().getClassLoader().getResource("/").getPath() + "/../../view.xls"; OutputStream output = null; FileInputStream fis = null; try { output = response.getOutputStream(); fis = new FileInputStream(filenamedownload); byte[] b = new byte[1024]; int i = 0; while((i = fis.read(b)) > 0) { output.write(b, 0, i); } output.flush(); } catch(Exception e) { System.out.println(\"Error!\"); e.printStackTrace(); } finally { if(fis != null) { fis.close(); fis = null; } if(output != null) { output.close(); output = null; } }%> 怎样快速显示查询结果的第一页 Boolean a=(Boolean)session.getAttribute("a")的作用 新手的困惑~ 关于jsp连接MYSQL数据库连接池的使用 你们能帮我推荐一个好的加密算法吗? (高分求救,不夠再加)用什麼方式可以驗證一個公式是否合法? jsf问题 类似ASP的response.redirect在JSP中怎么实现呢? 如何修改tomcat 4.1.18的配置,使修改过的Servlet能够及时重新加载! 菜鸟提问:怎样读取服务器上相应文件夹中的文件? include 包含文件问题 jsp单选按钮问题
<mime-mapping>
<extension>ppt</extension>
<mime-type>application/mspowerpoint</mime-type>
</mime-mapping>
2在jsp页头引入
<%@page contentType="application/msword;charset=gbk"%>
这是在浏览器中已word形式打开
<%@page contentType="application/vnd.ms-excel;charset=gbk"%>
这是以excel
<%
response.setContextType("application/vnd.ms-excel");%>
看行不?
如
FileInputStream is=new FileInputStream(new File("文件路径"));
response.setContentType("正确的mime类型");byte[] b=new byte[is.available()];
is.read(b);
response.getOutputStream().write(b);
这样就输出了
<a href="./word.doc">open the word</a>
在web.xml里面加上下面两句:
<mime-mapping>
<extension>doc</extension>
<mime-type>application/vnd.ms-word</mime-type>
</mime-mapping>
<mime-mapping>
<extension>xls</extension>
<mime-type>application/vnd.ms-excel</mime-type>
</mime-mapping>
<%
response.setContentType("application/vnd.ms-excel");
String xlsFile = this.getClass().getClassLoader().getResource("/").getPath() + "/../../view.xls";
OutputStream output = null;
FileInputStream fis = null;
try
{
output = response.getOutputStream();
fis = new FileInputStream(filenamedownload);
byte[] b = new byte[1024];
int i = 0;
while((i = fis.read(b)) > 0)
{
output.write(b, 0, i);
}
output.flush();
}
catch(Exception e)
{
System.out.println(\"Error!\");
e.printStackTrace();
}
finally
{
if(fis != null)
{
fis.close();
fis = null;
}
if(output != null)
{
output.close();
output = null;
}
}
%>