20171023_chr_classupload Struts2字节流完成文件上传
来源:互联网 发布:软件测试java面试题api 编辑:程序博客网 时间:2024/06/09 21:06
字节流完成文件上传
- /20171023_chr_classupload/src/nuc/sw/action/UploadAction.java
package nuc.sw.action;import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.IOException;import java.util.UUID;import com.opensymphony.xwork2.ActionSupport;public class UploadAction extends ActionSupport { private String title; private File upload; private String uploadContentType; private String uploadFileName; private String savePath; public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public File getUpload() { return upload; } public void setUpload(File upload) { this.upload = upload; } public String getUploadContentType() { return uploadContentType; } public void setUploadContentType(String uploadContentType) { this.uploadContentType = uploadContentType; } public String getUploadFileName() { return uploadFileName; } public void setUploadFileName(String uploadFileName) { this.uploadFileName = uploadFileName; } public String getSavePath() { return savePath; } public void setSavePath(String savePath) { this.savePath = savePath; } //处理上传文件的方法 public String upload() throws IOException{ //了解三个参数概念 System.out.println(upload); System.out.println(uploadContentType); System.out.println(uploadFileName); //完成上传,用字节流(二进制形式) try { FileInputStream fis=new FileInputStream(upload); String newFileName=UUID.randomUUID().toString()+"_"+uploadFileName; FileOutputStream fos=new FileOutputStream(savePath+"/"+newFileName); byte[] buffer=new byte[1024]; int len=0; while((len=fis.read(buffer))>0) { fos.write(buffer, 0, len); } } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } return "uploadOK"; }}
- /20171023_chr_classupload/src/struts.xml
<struts> <constant name="struts.multipart.saveDir" value="f:/upload"></constant> <!-- Add packages here --> <package name="uploadPackage" namespace="/" extends="struts-default"> <action name="uploadAction" class="nuc.sw.action.UploadAction" method="upload"> <interceptor-ref name="fileUpload"> <param name="allowedExtensions">txt,doc,docx,jpg</param> <param name="maximumSize">1024000</param> <param name="allowedTypes">text/plain</param> </interceptor-ref> <interceptor-ref name="defaultStack"></interceptor-ref> <param name="savePath">f:/uploadRealFile</param> <result name="uploadOK"> /success.jsp </result> <result name="input"> /upload.jsp </result> </action> </package></struts>
- /20171023_chr_classupload/WebContent/success.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>成功页</title></head><body> 上传成功!!!</body></html>
- /20171023_chr_classupload/WebContent/upload.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%><%@ taglib prefix="s" uri="/struts-tags" %><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>文件上传页</title></head><body> <s:fielderror></s:fielderror> <s:form action="uploadAction" method="post" enctype="multipart/form-data"> <s:textfield label="文件主题" name="title"></s:textfield> <s:file label="选择文件" name="upload"></s:file> <s:submit value="上传"></s:submit> </s:form></body></html>
阅读全文
0 0
- 20171023_chr_classupload Struts2字节流完成文件上传
- Struts2完成文件的上传功能实例
- struts2如何完成文件的上传
- struts2如何完成文件的上传?
- easyUi + jquery + common-file-upload +struts2完成文件进度条上传
- 上传文件保存字节流,下载
- 完成文件上传
- struts2上传文件(三) struts2上传文件
- 文章标题 使用ajaxFileupload+struts2完成文件的上传以及回显到jsp的链接地址
- [Struts2]Struts2的文件上传
- Struts2完成文件的下载
- Struts2完成文件的下载
- Struts2完成文件的下载
- plupload组件结合struts2完成上传
- Struts2的文件上传
- Struts2文件上传
- Struts2 上传文件实例
- struts2文件上传
- angularjs中form表单input脏值检测
- lintcode刷题记录合并排序数组 java
- vue解决POST跨域请求
- Android在Native层输出Log到本地文件
- 深度学习术语
- 20171023_chr_classupload Struts2字节流完成文件上传
- Android 自己实现 NavigationView [Design Support Library(1)]
- Python在数据科学中的应用(python 数据挖掘入门)
- RDD 中foreach与foreachPartition区别
- 类装载器(calssLoader)
- 在Tomcat中部署Web项目的操作方法(必看篇)
- 关于一些MySQL数据库的书籍
- 【linux】open函数创建新文件及umask函数使用
- 按要求编程22