Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!

kalai rathi

+ Follow
since Aug 16, 2011
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by kalai rathi


I am using Spring MVC. i have some form elements and image upload. before submit button i have to validate the image
(type, Height & width and size).
only accept JPG,JPEG,PNG,GIF file formats
400*400 ---height * width of the image
10000---size of the file.

Using jquery& ajax how to validate the image file?.Please help me. very Urgent Please

the project Details are as follows,

I have a form with some input elements and image upload button. using Spring MVC i validated the form elements and inserted into sql Database. successfully i completed. The modified requirement is before click a submit button i have to validate the image

instead of spring Validator i want to use Jquery -Ajax.

But here i attach sample program which i was tried to call spring mvc. i couldn't get the result. please any one try to help me.

here is my Controller

package test.mydir;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;

public class TestBeanController extends SimpleFormController {

protected ModelAndView onSubmit(HttpServletRequest request,
HttpServletResponse response, Object command, BindException errors)
throws Exception {
TestBean testBean=(TestBean)command;
String name=testBean.getName();

return new ModelAndView("success");


Here is My Service Class

package test.mydir;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;
import org.springframework.validation.BindException;
import org.springframework.web.servlet.mvc.SimpleFormController;

public class TestBeanService extends SimpleFormController {
private static final Logger log = Logger.getLogger(TestBeanService.class);

protected boolean isFormChangeRequest(HttpServletRequest request)
{"isfileupload method");
return isFileUploadRequest(request);


private boolean isFileUploadRequest(HttpServletRequest request) {"isfileupload method body");
return (!request.getParameter("name").equals(null));


protected void onFormChange(HttpServletRequest request,HttpServletResponse responses,
Object command,BindException bind){

TestBean testBean=(TestBean)command;"inside formchange");
PrintWriter out=new PrintWriter(System.out);




Here is my Bean

package test.mydir;

public class TestBean {
private String name;
private String name1;

public String getName1() {
return name1;

public void setName1(String name1) {
this.name1 = name1;

public TestBean() {


public String getName() {
return name;

public void setName(String name) { = name;


here is my Jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
<%@ taglib prefix="form" uri=""; %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">;
<script type="text/javascript" src="<%=request.getContextPath()%>jquery-1.6.2.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery.form.js"></script>
function call(){

var queryString = $('#myForm').formSerialize();

$.post('testBeanService.html', queryString,

<form:form id="myForm" method="post" commandName="event">
Name: <form:input path="name" id="name" onchange="call();" />
<form:input path="name1" id="name1" />
<input type="submit" value="Submit Comment" />

Here is my DispatcherServlet

<?xml version="1.0" encoding="UTF-8"?>

<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass"><value>org.springframework.web.servlet.view.JstlView</value></property>
<property name="prefix" value="/jsp/"/>
<property name="suffix" value=".jsp"></property>

<bean name="/testBeanService.html" class="test.mydir.TestBeanService"/>

<bean name="/eventCreation.html" class="test.mydir.TestBeanController">
<property name="commandName" value="event"/>
<property name="commandClass" value="test.mydir.TestBean"/>
<property name="formView" value="test"/>
<property name="successView" value="success"/>



9 years ago
I am new to Spring MVC

I am uploading image into DataBase. Before uploading the image,validate the image file format .
The file format should be (*.png,*.jpeg,*.jpg,*.gif) ,for other types must show error. this is the logic.

this is my jsp
<form:form commandName="event" id="eventForm" name="eventForm" method="post" enctype="multipart/form-data">

<label>Event Photo</label>
<input type="file" name="eventPhoto"/>
<form:errors path="eventPhoto" cssClass="error" />

My validation here.

errors.rejectValue("eventPhoto", "filetype.required");

the above code has worked in Safari, Firefox, Chrome. Except IE

when i upload *.bmp image in IE it accepts as --- image/pjpeg

it doesn't show error. IE accepts all image formats. This is the problem.

problem 2)

validate the image dimension ( height & weight) like 400*400

9 years ago