Search code examples
strutsstruts-1struts-validationstruts1

Content type not working in struts


This is written in my validate method. The check for size and empty upload is working but content type is not, am i missing something ?

public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
    ActionErrors errors = new ActionErrors();

    if(file1.getFileSize()==0)
    {
    errors.add("file1", new ActionMessage("error.file.required"));
    }
    else if(!file1.getContentType().equals("audio/mpeg"));
    {
    errors.add("file1",new ActionMessage("error.file.type"));
    }
    if(file1.getFileSize()>51200)
    {
    errors.add("file1",new ActionMessage("error.file.size"));
    }

    return errors;

Solution

  • I think your else if condition statement is missing because of ";" sign as the following :

    else if(!file1.getContentType().equals("audio/mpeg"));
    

    It should be as the following :

    else if(!file1.getContentType().equals("audio/mpeg"))