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 javax.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
45
46
47
48 protected String theText;
49
50
51
52
53 protected String queryParam;
54
55
56
57
58 protected boolean writeFile;
59
60
61
62
63 protected FormFile theFile;
64
65
66
67
68 protected String filePath;
69
70
71
72
73 public String getTheText() {
74 return theText;
75 }
76
77
78
79
80 public void setTheText(String theText) {
81 this.theText = theText;
82 }
83
84
85
86
87 public String getQueryParam() {
88 return queryParam;
89 }
90
91
92
93
94 public void setQueryParam(String queryParam) {
95 this.queryParam = queryParam;
96 }
97
98
99
100
101 public FormFile getTheFile() {
102 return theFile;
103 }
104
105
106
107
108 public void setTheFile(FormFile theFile) {
109 this.theFile = theFile;
110 }
111
112
113
114
115 public void setWriteFile(boolean writeFile) {
116 this.writeFile = writeFile;
117 }
118
119
120
121
122 public boolean getWriteFile() {
123 return writeFile;
124 }
125
126
127
128
129 public void setFilePath(String filePath) {
130 this.filePath = filePath;
131 }
132
133
134
135
136 public String getFilePath() {
137 return filePath;
138 }
139
140 public void reset() {
141 writeFile = false;
142 }
143
144
145
146
147
148 public ActionErrors validate(
149 ActionMapping mapping,
150 HttpServletRequest request) {
151
152 ActionErrors errors = super.validate(mapping, request);
153
154
155 Boolean maxLengthExceeded =
156 (Boolean) request.getAttribute(
157 MultipartRequestHandler.ATTRIBUTE_MAX_LENGTH_EXCEEDED);
158
159 if ((maxLengthExceeded != null) && (maxLengthExceeded.booleanValue())) {
160 if (errors == null) {
161 errors = new ActionErrors();
162 }
163 errors.add(
164 ActionMessages.GLOBAL_MESSAGE ,
165 new ActionMessage("maxLengthExceeded"));
166 errors.add(
167 ActionMessages.GLOBAL_MESSAGE ,
168 new ActionMessage("maxLengthExplanation"));
169 }
170 return errors;
171
172 }
173 }