package com.servlet;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.sun.org.apache.xalan.internal.xsltc.trax.OutputSettings;
import com.word.WordForFtp;
public class mypdf extends HttpServlet {
/**
* Constructor of the object.
*/
public mypdf() {
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 {
this.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 {
//拿到服务器存储路径
String path =request.getSession().getServletContext().getRealPath("/");
String filepath = path+"pdf\\";
//拿到前台传入文件路径
String wordfilepath = request.getParameter("wordpath");
String pat = wordfilepath.substring(wordfilepath.lastIndexOf(".")+1);
if(pat.equals("pdf")){
//PDF文件是复制
String lj = wordfilepath.replace("http://localhost:8080/pageoffice/", path);
File file = new File(lj);
FileInputStream in = new FileInputStream(file);
String target1 = filepath+"span5.pdf";
FileOutputStream out = new FileOutputStream(target1);
byte[] b = new byte[1024];
while(in.read(b) > 0){
out.write(b);
}
in.close();
out.flush();
out.close();
}else{
//word文件时转换进行复制
System.out.println(wordfilepath);
response.setContentType("text/html");
String source1 = wordfilepath;
String target1 = filepath+"test3.pdf";
WordForFtp pdf = new WordForFtp();
pdf.word2pdf(source1, target1);
}
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}
}
javaweb预览word与pdf文件控件为免费控件
需积分: 10 198 浏览量
2016-08-25
17:51:54
上传
评论 3
收藏 5.05MB ZIP 举报
qq_23196585
- 粉丝: 0
- 资源: 1
最新资源
- 《CKA/CKAD应试指南/从docker到kubernetes 完全攻略》学习笔记 第1章docker基础(1.1-1.4)
- 基于python实现的水下压缩空气储能互补系统建模仿真与经济效益分析+源代码+论文
- 华中科技大学-自然语言处理实验,Bi-LSTM+CRF的中文分词框架,并且利用基于深度学习的方法进行中文命名实体识别++源码报告
- 基于动态罚函数的铁路车流分配与径路优化模型python源码
- 鱼群算法求解组环问题python源码+文档说明
- 基于决策优化的多波束测深测线规划模型MATLAB代码
- 课程设计-基于python实现的多目标优化算法求解带时间窗的车辆路径规划问题+源代码+文档说明+界面截图+pptx
- 基于通信信号与通信系统的MATLAB仿真源码-课程设计
- 嵌入式-信号机制(概念,发送,定时,捕捉,SIGCHLD 信号实现回收子进程)
- c语言管理系统大一大二笔记
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈