Content type not working in struts
-
05-06-2021 - |
سؤال
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;
المحلول
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"))
نصائح أخرى
done with:
else if(!file1.getContentType().equals("audio/mp3")) { ---- }
I checked the type of the the fileuploaded by: String ctype = file1.getContentType();
without puting any validation (i.e upload any file) and printed it on the jsp page. From there i came to know that its audio/mp3. Now all validations are working. /
لا تنتمي إلى StackOverflow