1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.apache.struts.webapp.upload;
23
24 import jakarta.servlet.http.HttpServletRequest;
25
26 import org.apache.struts.action.ActionMapping;
27 import org.apache.struts.action.ActionMessage;
28 import org.apache.struts.action.ActionMessages;
29 import org.apache.struts.action.ActionErrors;
30 import org.apache.struts.validator.ValidatorForm;
31 import org.apache.struts.upload.FormFile;
32 import org.apache.struts.upload.MultipartRequestHandler;
33
34
35
36
37
38
39
40
41
42
43 public class UploadForm extends ValidatorForm {
44 private static final long serialVersionUID = 9109939239360280904L;
45
46
47
48
49 protected String theText;
50
51
52
53
54 protected String queryParam;
55
56
57
58
59 protected boolean writeFile;
60
61
62
63
64 protected FormFile theFile;
65
66
67
68
69 protected String filePath;
70
71
72
73
74 public String getTheText() {
75 return theText;
76 }
77
78
79
80
81 public void setTheText(String theText) {
82 this.theText = theText;
83 }
84
85
86
87
88 public String getQueryParam() {
89 return queryParam;
90 }
91
92
93
94
95 public void setQueryParam(String queryParam) {
96 this.queryParam = queryParam;
97 }
98
99
100
101
102 public FormFile getTheFile() {
103 return theFile;
104 }
105
106
107
108
109 public void setTheFile(FormFile theFile) {
110 this.theFile = theFile;
111 }
112
113
114
115
116 public void setWriteFile(boolean writeFile) {
117 this.writeFile = writeFile;
118 }
119
120
121
122
123 public boolean getWriteFile() {
124 return writeFile;
125 }
126
127
128
129
130 public void setFilePath(String filePath) {
131 this.filePath = filePath;
132 }
133
134
135
136
137 public String getFilePath() {
138 return filePath;
139 }
140
141 public void reset() {
142 writeFile = false;
143 }
144
145
146
147
148
149 public ActionErrors validate(
150 ActionMapping mapping,
151 HttpServletRequest request) {
152
153 ActionErrors errors = super.validate(mapping, request);
154
155
156 Boolean maxLengthExceeded =
157 (Boolean) request.getAttribute(
158 MultipartRequestHandler.ATTRIBUTE_MAX_LENGTH_EXCEEDED);
159
160 if ((maxLengthExceeded != null) && (maxLengthExceeded.booleanValue())) {
161 if (errors == null) {
162 errors = new ActionErrors();
163 }
164 errors.add(
165 ActionMessages.GLOBAL_MESSAGE ,
166 new ActionMessage("maxLengthExceeded"));
167 errors.add(
168 ActionMessages.GLOBAL_MESSAGE ,
169 new ActionMessage("maxLengthExplanation"));
170 }
171 return errors;
172
173 }
174 }