Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

Can anyone help to call jquery in springMVC

Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator

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"/>



Posts: 17347
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Please check your private messages for an important JavaRanch message.


I once met a man from Nantucket. He had a tiny ad
a bit of art, as a gift, the permaculture playing cards
    Bookmark Topic Watch Topic
  • New Topic