67,512
社区成员
发帖
与我相关
我的任务
分享
public class Upload extends ActionSupport {
private static final long serialVersionUID = -4848248679889814408L;
/** 文件对象 */
private List<File> Filedata;
/** 文件名 */
private List<String> FiledataFileName;
/** 文件内容类型 */
private List<String> FiledataContentType;
private String name;
private JComPDFConverter jconPDFConverter;
public static void main(String[] args) {
String inputFile = "E:\\javatest\\javaworkspace10\\upload\\WebRoot\\uploads\\a8dd8cba-879b-44af-b3d4-ce4e1b1b4ab9.doc";
String pdfFile = "E:\\javatest\\javaworkspace10\\upload\\WebRoot\\uploads\\a8dd8cba-879b-44af-b3d4-ce4e1b1b4ab9.pdf";
String swfFile = "E:\\javatest\\javaworkspace10\\upload\\WebRoot\\uploads\\a8dd8cba-879b-44af-b3d4-ce4e1b1b4ab9.swf";
JComPDFConverter.word2PDF(inputFile, pdfFile);
SWFConverter swfConverter = new SWFToolsSWFConverter();
swfConverter.convert2SWF(pdfFile, swfFile);
}
public String doUpload() {
ActionContext ac = ActionContext.getContext();
HttpServletRequest request = ServletActionContext.getRequest();
//System.out.println(" name " + request.getAttribute("name"));
//System.out.println(" name " + request.getParameter("name"));
ServletContext sc = (ServletContext) ac
.get(ServletActionContext.SERVLET_CONTEXT);
String savePath = sc.getRealPath("/");
savePath = savePath + "uploads\\";
// String filePath = "conf\\template\\excel\\demo.xls";
// String realPath = request.getSession().getServletContext()
// .getRealPath(filePath);
File f1 = new File(savePath);
if (!f1.exists()) {
f1.mkdirs();
}
int size = Filedata.size();
if (size == 0)
return ERROR;
String extName = null;
String name = null;
for (int i = 0; i < size; i++) {
extName = FiledataFileName.get(i).substring(
FiledataFileName.get(i).lastIndexOf("."));
name = UUID.randomUUID().toString();
System.out.println(" path " + savePath + name + extName);
// 定义文件
String inputFile = savePath + name + extName;
String pdfFile = savePath + name + ".pdf";
String swfFile = savePath + name + ".swf";
System.out.println(pdfFile);
System.out.println(swfFile);
File file = new File(savePath + name + extName);
try {
FileUtils.copyFile(Filedata.get(i), file);
if (extName.equals(".doc")) {
jconPDFConverter = new JComPDFConverter();
JComPDFConverter.word2PDF("E:\\javatest\\javaworkspace10\\upload\\WebRoot\\uploads\\a8dd8cba-879b-44af-b3d4-ce4e1b1b4ab9.doc", "E:\\javatest\\javaworkspace10\\upload\\WebRoot\\uploads\\a8dd8cba-879b-44af-b3d4-ce4e1b1b4ab9.pdf");
// SWFConverter swfConverter = new SWFToolsSWFConverter();
// swfConverter.convert2SWF(pdfFile,
// swfFile);
}
} catch (IOException e) {
e.printStackTrace();
}
}
HttpServletResponse response = ServletActionContext.getResponse();
try {
response.getWriter().print(name + extName);
} catch (IOException e) {
e.printStackTrace();
}
return SUCCESS;
// NULL
}