-
validation of File Upload in Struts
I want to validate the field "multipart/form-data" defined in my JSP file. If the user did not select a file, I am going to send out a warning for them.
The way I do it is from the ActionForm bean class. I have the following code:
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
// Check for input: theFile, which is the multipart/form-data field
ActionErrors errors = new ActionErrors();
if (theFile == null || theFile.equals("")) {
errors.add("upload file", new ActionError("error.noFileSpecified"));
}
return errors;
}
}
But apparently, (theFile==null) or (theFile.equals("")) does not work for "multipart/form-data" field. I test the same thing for a text field, it works ok.
Can anybody tell me how to do it if you want to validate the input value of the "multipart/form-data" field?
After I get the data of the file, how can I save the data to the server? Can anybody send me an example?
thank you.
Similar Threads
-
Replies: 3
Last Post: 08-26-2007, 12:11 AM
-
By chinmoy paul in forum Java
Replies: 0
Last Post: 08-28-2006, 01:58 AM
-
By hprasetya in forum Java
Replies: 0
Last Post: 06-07-2006, 05:48 AM
-
Replies: 146
Last Post: 08-12-2002, 10:40 PM
-
By Paul in forum Database
Replies: 0
Last Post: 08-22-2000, 10:54 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks