/*******************************************************/
>参考root:\struts-2.2.3.1-all\struts-2.2.3.1\
apps\
struts2-showcase
\fileupload
/*******************************************************/
http://code.google.com/intl/zh-CN/eclipse/docs/install-from-zip.html
http://code.google.com/intl/zh-CN/eclipse/docs/install-from-zip.html
http://code.google.com/p/sfeir/downloads/detail?name=gwt-2.4.beta.r10416.zip&can=2&q=
>0.struts2单个文件上传
>******************************<
>必要的jar包
commons-fileupload-n.n.n.jar
commons-io-n.n.n.jar
>可选配置参数
/** 指定上传的文件保存的临时目录*/
<constant name="struts.multipart.saveDir" value="F:\\struts\\strutsworkspace\\struts2\\uploadfile">
/** 指定上传文件的最大字节数*/
<constant name="struts.multipart.maxSize" value="5000000"></constant>
>是否需要配置上传拦截器
不需要因为默认(defaultStack)的中已经有
<interceptor name="fileUpload" class="org.apache.struts2.interceptor.FileUploadInterceptor"/>这个上传拦截器
>******************************<
>1.action继承自action的子类或者实现action接口
/*********************************************************************************************/
//public class FileUpLoadAction extends ActionSupport {
// private File upload; /** 上传的文件引用*/
// private String uploadFileName;/** 上传的文件的名字*/
// private String uploadFileContentType;/** 上传的文件的类型*/
// 需要注意的是[文件名字][文件内容类型]前面都要加上上传文件引用的变量名
//<s:form enctype="multipart/form-data" method="post" action="upload/fileUpLoadAction!show_upload">
// /** 设置好表单提交的类型和数据内容类型*/
// <s:file name="upload" label="file"/> /** label相当于按钮的value值,name必须是在action中定义的接收文件的属性名字*/
// <s:submit value="submit"/>
//</s:form>
// public File getUpload() {
// return upload;
// }
//
// public void setUpload(File upload) {
// this.upload = upload;
// }
//
// public String getUploadFileName() {
// return uploadFileName;
// }
//
// public void setUploadFileName(String uploadFileName) {
// this.uploadFileName = uploadFileName;
// }
//
// public String getUploadFileContentType() {
// return uploadFileContentType;
// }
//
// public void setUploadFileContentType(String uploadFileContentType) {
// this.uploadFileContentType = uploadFileContentType;
// }
//
// @Override
// public void validate() {
// this.clearActionErrors();
// this.clearErrors();
// this.clearFieldErrors();
// }
//
// /** 验证文件是否上传*/
// public String show_upload(){
// if (null!=this.upload) {
// System.out.println("xxxxxxxxxxxxxxx");
// }else{
// System.out.println("0000000000000000");
// }
// return this.SUCCESS;
// }
//}
/*********************************************************************************************/
>2.struts2多个文件上传
/*********************************************************************************************/
//public class FileUpLoadAction extends ActionSupport {
// private File uploads[];
// private String uploadFileNames[];
// private String uploadContentTypes[];
//
// //注意需要把s去掉
// //然后进行get和set
// public File[] getUpload() {
// return uploads;
// }
// public void setUpload(File[] uploads) {
// this.uploads = uploads;
// }
// public String[] getUploadFileName() {
// return uploadFileNames;
// }
// public void setUploadFileName(String[] uploadFileNames) {
// this.uploadFileNames = uploadFileNames;
// }
// public String[] getUploadContentType() {
// return uploadContentTypes;
// }
// public void setUploadContentType(String[] uploadContentTypes) {
// this.uploadContentTypes = uploadContentTypes;
// }
//
// public String show_upload() throws Exception {
// System.out.println("\n\n upload2");
// System.out.println("files:");
// for (File u: uploads) {
// System.out.println("*** "+u+"\t"+u.length());
// }
// System.out.println("filenames:");
// for (String n: uploadFileNames) {
// System.out.println("*** "+n);
// }
// System.out.println("content types:");
// for (String c: uploadContentTypes) {
// System.out.println("*** "+c);
// }
// System.out.println("\n\n");
// return SUCCESS;
// }
//}
/*********************************************************************************************/