Extjs4.0实现文件下载
来源:互联网 发布:win ubuntu 双系统 编辑:程序博客网 时间:2024/06/06 17:19
Extjs4.0实现文件下载
1、前台:{
text: "用户手册",
id: "yhsc",
icon: 'images/ico/common/help.png',
handler: function() {
window.open("fileServlet","用户手册").focus();
}
}
2、后台(以servlet为例)
1》web.xml文件配置:
<servlet>
<description>This is the description of my J2EE component</description>
<display-name>This is the display name of my J2EE component</display-name>
<servlet-name>FileServlet</servlet-name>
<servlet-class>com.gistone.util.FileServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>FileServlet</servlet-name>
<url-pattern>/fileServlet</url-pattern>
</servlet-mapping>
2》FileServlet.java文件配置:
package com.gistone.util;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class FileServlet extends HttpServlet {
private static final String RJD_ExcelTemplate_URL = "use/userManual.pdf"; //配置文件所在路径
/**
* Constructor of the object.
*/
public FileServlet() {
super();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request,response);
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try{
File f = new File(request.getRealPath("/") + RJD_ExcelTemplate_URL);
FileInputStream input = new FileInputStream(f);
response.reset();
response.setContentType("application/pdf;charset=UTF-8");
response.addHeader("Content-Disposition", "attachment;filename=\"" + new String(RJD_ExcelTemplate_URL.substring(RJD_ExcelTemplate_URL.lastIndexOf("/")+1).getBytes("GBK"), "ISO8859_1") + "\"");
OutputStream out = response.getOutputStream();
byte[] b = new byte[1024];
int len = 0;
while ((len = input.read(b)) != -1) {
out.write(b, 0, len);
}
}catch(FileNotFoundException e1)
{
System.out.println("没有找到您要的文件");
}
catch(Exception e)
{
System.out.println("系统错误,请及时与管理员联系");
}
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}
}
- Extjs4.0实现文件下载
- Extjs4 实现文件的下载(后台使用struts2实现)
- extjs4.0 文件上传
- ExtJs4.0实现饼图
- Extjs4.0学习笔记(文件引用)
- Extjs4.0学习笔记(文件引用)
- ExtJS4.0中Excel文件导入grid
- Ext+Struts2.0实现文件下载
- 基于tapestry5.0实现的文件下载
- PHP实现文件下载
- [Servlet] 实现文件下载
- JSP实现文件下载
- jsp实现文件下载
- struts实现文件下载
- JSP实现文件下载
- Servlet实现文件下载
- servlet实现文件下载
- struts2实现文件下载
- SDL Game Development-第2章-1.BMP的原样显示
- 用MFC视频控件播放视频
- Fiddler用法之拦截替换
- thinkphp 独立分组公共控制器
- NGINX部署图片服务器
- Extjs4.0实现文件下载
- Exception Name: No result defined for action XXXAction and result input
- Android软键盘 隐藏or显示
- c语言字符串与整数之间的转换
- java Swing组件大全
- hadoop 中文wiki
- 如何取datatable的前N行
- GitHub“最受欢迎的开源项目” TOP 50 android开源项目 直接拿来用
- ACM竞赛题:制作万年历法二