Here i have demo.jsp page where i'm uploading the image for this i have written javascript validation code for jpg,png and gif but if image type is other than that we cant write for every type in conditon so is there any alternate method to do this?
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>ImageResizing</title>
<script>
function vlidate() {
var fileName = document.getElementById("Imgfile").value;
var file_extension = fileName.split('.').pop();
var newWidth = document.getElementById("newWidth").value;
var newHeight = document.getElementById("newHeight").value;
//alert(fileName);
//alert(file_extension);
if (file_extension !== "jpg" || file_extension !== "png" || file_extension !== "gif") {
alert("Choose Valid image");
}
else if ((file_extension == "jpg" || file_extension == "png" || file_extension == "gif") && (newWidth.length != "" && newHeight.length != "")) {
//alert("Go ahead");
document.getElementById("uploadImgForm").submit();
}
}
</script>
</head>
<body bgcolor="#ABD3EB">
<%
out.println("<form method='post' action='FileUploadServlet' enctype='multipart/form-data' id='uploadImgForm' name='uploadImgForm'>");
out.println("<h2>Image Resizing</h2>");
out.println("<table>");
out.println("<tr><td><input type='file' id='Imgfile' name='Imgfile'></td></tr>");
out.println("<tr><td></td></tr>");
out.println("<tr><td>New Width:</td><td><input type='text' id='newWidth' name='newWidth'</td></tr>");
out.println("<tr><td>New Height:</td><td><input type='text' id='newHeight' name='newHeight'</td></tr>");
out.println("<tr><td></td></tr>");
out.println("<tr><td><input type='button' value='Upload Image' onclick='vlidate()' ></td></tr>");
//out.println("<tr><td><input type='submit' value='Upload Image' ></td></tr>");
out.println("</table>");
out.println("</form>");
%>
</body>