没有网站可以做备案吗网站推广网络
web/
2025/10/7 18:40:08/
文章来源:
没有网站可以做备案吗,网站推广网络,Mac怎么搭建网站开发环境,用搬瓦工搭建wordpress注意点 private File image;//对应的就是表单中文件上传的那个输入域的名称#xff0c;Struts2框架会封装成File类型的private String imageFileName;// 上传输入域FileName 文件名private String imageContentType;// 上传文件的MIME类型 单个文件 1 package cn.itcast.ac…注意点 private File image;//对应的就是表单中文件上传的那个输入域的名称Struts2框架会封装成File类型的private String imageFileName;// 上传输入域FileName 文件名private String imageContentType;// 上传文件的MIME类型 单个文件 1 package cn.itcast.action;2 3 import java.io.File;4 import java.io.FileInputStream;5 import java.io.FileNotFoundException;6 import java.io.FileOutputStream;7 import java.io.InputStream;8 import java.io.OutputStream;9 import java.io.Serializable;
10
11 import javax.servlet.ServletContext;
12
13 import org.apache.commons.io.FileUtils;
14 import org.apache.struts2.ServletActionContext;
15
16 import com.opensymphony.xwork2.ActionContext;
17 import com.opensymphony.xwork2.ActionSupport;
18
19 public class UploadAction1 extends ActionSupport implements Serializable {
20
21 private File image;//对应的就是表单中文件上传的那个输入域的名称Struts2框架会封装成File类型的
22 private String imageFileName;// 上传输入域FileName 文件名
23 private String imageContentType;// 上传文件的MIME类型
24
25 public File getImage() {
26 return image;
27 }
28
29
30
31 public void setImage(File image) {
32 this.image image;
33 }
34
35
36
37 public String getImageFileName() {
38 return imageFileName;
39 }
40
41
42
43 public void setImageFileName(String imageFileName) {
44 this.imageFileName imageFileName;
45 }
46
47
48
49 public String getImageContentType() {
50 return imageContentType;
51 }
52
53
54
55 public void setImageContentType(String imageContentType) {
56 this.imageContentType imageContentType;
57 }
58
59
60
61 public String execute(){
62 System.out.println(imageContentType);
63 try {
64 //处理实际的上传代码
65 //找到存储文件的真实路径
66 // System.out.println(imageFileName);
67 ServletContext sc ServletActionContext.getServletContext();
68 String storePath sc.getRealPath(/files);
69 //构建输入输出流
70 // OutputStream out new FileOutputStream(storePath\\imageFileName);
71 // InputStream in new FileInputStream(image);
72 // byte b[] new byte[1024];
73 // int len -1;
74 // while((lenin.read(b))!-1){
75 // out.write(b, 0, len);
76 // }
77 // out.close();
78 // in.close();
79
80 FileUtils.copyFile(image, new File(storePath,imageFileName));
81
82 ActionContext.getContext().put(message, 上传成功);
83 return SUCCESS;
84 } catch (Exception e) {
85 e.printStackTrace();
86 return ERROR;
87 }
88 }
89 } jsp中 1 body
2 form action${pageContext.request.contextPath}/upload/upload1.action methodpost enctypemultipart/form-data
3 文件input typefile nameimage/br/
4 input typesubmit value上传/
5 /form
6 /body 多个文件上传 1 package cn.itcast.action;2 3 import java.io.File;4 import java.io.FileInputStream;5 import java.io.FileNotFoundException;6 import java.io.FileOutputStream;7 import java.io.InputStream;8 import java.io.OutputStream;9 import java.io.Serializable;
10
11 import javax.servlet.ServletContext;
12
13 import org.apache.commons.io.FileUtils;
14 import org.apache.struts2.ServletActionContext;
15
16 import com.opensymphony.xwork2.ActionContext;
17 import com.opensymphony.xwork2.ActionSupport;
18
19 public class UploadAction2 extends ActionSupport implements Serializable {
20
21 private File[] images;//对应的就是表单中文件上传的那个输入域的名称Struts2框架会封装成File类型的
22 private String[] imagesFileName;// 上传输入域FileName 文件名
23 private String[] imagesContentType;// 上传文件的MIME类型
24
25
26
27 public File[] getImages() {
28 return images;
29 }
30
31
32
33 public void setImages(File[] images) {
34 this.images images;
35 }
36
37
38
39 public String[] getImagesFileName() {
40 return imagesFileName;
41 }
42
43
44
45 public void setImagesFileName(String[] imagesFileName) {
46 this.imagesFileName imagesFileName;
47 }
48
49
50
51 public String[] getImagesContentType() {
52 return imagesContentType;
53 }
54
55
56
57 public void setImagesContentType(String[] imagesContentType) {
58 this.imagesContentType imagesContentType;
59 }
60
61
62
63 public String execute(){
64 try {
65
66 if(images!nullimages.length0){
67 ServletContext sc ServletActionContext.getServletContext();
68 String storePath sc.getRealPath(/files);
69 for(int i0;iimages.length;i)
70 FileUtils.copyFile(images[i], new File(storePath,imagesFileName[i]));
71 }
72 ActionContext.getContext().put(message, 上传成功);
73 return SUCCESS;
74 } catch (Exception e) {
75 e.printStackTrace();
76 return ERROR;
77 }
78 }
79 } jsp中 1 body
2 form action${pageContext.request.contextPath}/upload/upload2.action methodpost enctypemultipart/form-data
3 文件1input typefile nameimages/br/
4 文件2input typefile nameimages/br/
5 input typesubmit value上传/
6 /form
7 /body struts.xml中配置 设置文件上传大小 1 constant namestruts.multipart.maxSize value52428800/constant 1 package nameupload namespace/upload extendsmypackage
2 action nameupload1 classcn.itcast.action.UploadAction1 methodexecute
3 result namesuccess/success.jsp/result
4 /action
5 action nameupload2 classcn.itcast.action.UploadAction2 methodexecute
6 result namesuccess/success.jsp/result
7 /action
8 /package 转载于:https://www.cnblogs.com/friends-wf/p/3766374.html
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/web/88625.shtml
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!