日期:2014-05-18  浏览次数:20695 次

请教把jsp页内容导出成word文件
把本页内容导出成word文件

------解决方案--------------------
<%@page contentType= "text/html;Charset=GB2312 "%>
<html> <body=cyan> <font size=2>
<p> 在学习response对象的setContentType方法
<form action= " " method= "post " name=form>
<p> 当前页面用MS-Word显示吗?
<input type= "submit " value= "MS-Word显示 "name= "submit ">
<p> 当前页面用MS-Powerpoint显示吗?
<input type= "submit " value= "MS-Powerpoint显示 "name= "submit ">
<p> 当前页面用MS-Excel显示吗?
<input type= "submit " value= "MS-Excel显示 "name= "submit ">
</form>
<% String str=request.getParameter( "submit ");
if(str==null){
str= " ";
}
if(str.equals( "MS-Word显示 ")){
response.setContentType( "application/msword ");
}
if(str.equals( "MS-Powerpoint显示 ")){
response.setContentType( "application/vnd.ms-powerpoint ");
}
if(str.equals( "MS-Excel显示 ")){
response.setContentType( "application/vnd.ms-excel ");
}

%>

让response对象调用setContentType(String s)方法来改变contentType 的属性值该方法设置响应的mime类型,参数s可取值text/html,text/plain,image/gif,image/jpeg,image/x-xbitmap,application/vnd.ms-powerpoint,application/vnd.ms-excel,application/msword等

------解决方案--------------------
学习中