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.