Spring MVC Fast Tutorial: Form Processing

What are we going to build?

A form to create a new car.

Spring Form Processing

Form Controller

Struts controllers extend Action whereas Spring controllers extend/implement a Controller class/interface. There are many of them. The most basic is Controller, used previously. To process a form, SimpleFormController is generally used.

A form controller has two roles:

  • initialize the form's initial values
  • process/persist submitted user input:

Command

A Command object is used to store the form values: it's equivalent to a Struts Action Form. However, it doesn't have to extend nor implement anything. So it's even possible to directly use the model class! (Car in our example)

Manager Classes

We need a method to create a car in 'WEB-INF/src/springmvc/service/CarManager.java':

public Car createCar(Car c) {
	Car car = new Car();
	car.setId((long)carList.size() + 1);
	car.setBrand(c.getBrand());
	car.setModel(c.getModel());
	car.setPrice(c.getPrice());
 
	carList.add(car);
 
	return car;
}

We also need a manager for brands, 'WEB-INF/src/springmvc/service/BrandManager.java':

package springmvc.service;
 
import java.util.LinkedList;
import java.util.List;
 
import springmvc.model.Brand;
 
public class BrandManager {
 
	private static List<Brand> brandList;
 
	static {
		Brand brand1 = new Brand();
		brand1.setId((long)1);
		brand1.setName("Mercedes");
		brand1.setCountry("Germany");		
 
		Brand brand2 = new Brand();
		brand2.setId((long)2);
		brand2.setName("Peugeot");
		brand2.setCountry("France");		
 
		brandList = new LinkedList<Brand>();
		brandList.add(brand1);
		brandList.add(brand2);		
	}
 
	public List<Brand> getBrandList() {
		return brandList;
	}	
 
	public Brand getBrandById(Long id) {
		for (Brand brand : brandList) {
			if (brand.getId().equals(id))
				return brand;
		}
		return null;
	}
}

Let's not frown upon the data duplication, it's not the point here :-)

Controller

In 'WEB-INF/springmvc-servlet.xml', we declare a new URL and its Controller:

<bean name="/new_car.html" class="springmvc.web.CarNewController">
    <property name="commandClass" value="springmvc.model.Car"/>
    <property name="formView" value="carNew"/>
    <property name="successView" value="list_cars.html"/>
</bean>
  • commandClass: the Command class
  • formView: the form view name
  • successView: where we go after the form has been successfully submitted

We now create this Controller: 'WEB-INF/src/springmvc/web/CarNewController.java':

package springmvc.web;
 
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;
 
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
 
import org.springframework.web.bind.ServletRequestDataBinder;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;
import org.springframework.web.servlet.view.RedirectView;
 
import springmvc.model.Brand;
import springmvc.model.Car;
import springmvc.service.BrandManager;
import springmvc.service.CarManager;
 
public class CarNewController extends SimpleFormController {
 
    @Override
    protected Object formBackingObject(HttpServletRequest request) throws Exception {
    	Car defaultCar = new Car();
    	defaultCar.setModel("new model");
    	defaultCar.setPrice(new BigDecimal(15000));
    	return defaultCar;
    }
 
    @Override
    protected Map referenceData(HttpServletRequest request) throws Exception {
    	Map<Object, Object> dataMap = new HashMap<Object, Object>();
    	BrandManager brandManager = new BrandManager();
    	dataMap.put("brandList", brandManager.getBrandList());
    	return dataMap;
    }
 
    @Override
    protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception {
    	binder.setDisallowedFields(new String[] {"brand"});
 
    	Car car = (Car)binder.getTarget();
 
    	// set car's brand from request parameter brand id
    	BrandManager brandManager = new BrandManager();    	
    	Long brandId = null;
    	try {
	    	brandId = Long.parseLong(request.getParameter("brand"));
		} catch (Exception e) {}		
		if (brandId != null) {
			Brand brand = brandManager.getBrandById(brandId);
			car.setBrand(brand);
		}    
    }
 
    @Override
    public ModelAndView onSubmit(Object command) throws ServletException {
    	CarManager carManager = new CarManager();
    	carManager.createCar((Car)command);
 
    	return new ModelAndView(new RedirectView(getSuccessView()));
    }
 
}

These methods are called before the form is displayed:

  • formBackingObject: initialize the Command used to init the form.
  • referenceData: set the view attributes (using a Map)

These are called after:

  • initBinder: prevent Spring to do some bindings and so them by ourselves if needed. Here we used the brand id parameter to set the actual Brand.
  • onSubmit: the main code. In this case, we used the command object, which is a Car, to create a new Car.

View

Let's now create the view 'jsp/carNew.jsp':

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
 
<html>
<body>
	<h1>New Car</h1>
 
	<form:form method="post">
 
		Brand<br />
		<form:select path="brand">
		   <form:options items="${brandList}" itemLabel="name" itemValue="id" />
		</form:select>
		<br /><br />
 
		Model<br />
		<form:input path="model"/><br /><br />
 
		Price<br />
		<form:input path="price"/><br /><br />
 
		<input type="submit" value="Submit">
 
	</form:form>
</body>
</html>

It's blissfully simple. We use the brandList attribute defined in referenceData method in the controller to populate the form select.

Result

We rebuild (ant), relaunch Tomcat and check it's working: http://localhost:8180/springmvc/new_car.html

Summary

Your project should now look like that:

You can download it here.

This is how Spring processes a form. Some advantages compared to Struts:

  • controller code is divided between several methods to override only when necessary
  • model beans can be used as form beans: no extra classes to write. For complex attributes (like brand in our example), we can override Spring and do the bindings ourselves.
  • xml configuration is clear and straightforward

Previous: Model View Controller --- Up: Spring Fast Tutorial --- Next: Form Validation

 

Feedback

Good ,we understand easyly,Good Examples. I think U can Give Some More Explanation(process of the code)about coding .
pasha
May 20, 2008
#1
Nice tutorial, appreciate if more examples added related to spring DAO and transection management.
Rakesh
Nov 11, 2008
#2
Great!!!
Chetan
Dec 1, 2008
#3
Very Good example.. In the browser I am getting the correct result. But at the server I got java.lang.NumberFormatException: null when I opened the application in browser. any help please..
Venkat
Dec 4, 2008
#4
Really good example, but how can I preselect a value for <form:select ? Thx a lot.
Daniel
Dec 5, 2008
#5
I found the answer, if we bind the object on formBackingObject, it will automatically showing the value in db as selected. This simple example are AAA++++++.
Daniel
Dec 6, 2008
#6
Very good example! It helped me a lot.
Enrico
Jan 16, 2009
#7
Excellent tutorial, anyone can easily understood. Please add more examples. Christopher
Christopher
Jan 20, 2009
#8
Nice!
Partha
Feb 17, 2009
#9
exception javax.servlet.ServletException: Servlet.init() for servlet satyam threw exception org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148) org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869) org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664) org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527) org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80) org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684) java.lang.Thread.run(Unknown Source) root cause java.lang.NoClassDefFoundError: org/springframework/beans/PropertyAccessorFactory org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:114) javax.servlet.GenericServlet.init(GenericServlet.java:211) org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148) org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869) org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664) org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527) org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80) org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684) java.lang.Thread.run(Unknown Source) I'm getting this error when i run the Hello_world application. Kindly help!!!
shruthi
Feb 19, 2009
#10
Shruthi, try "ant clean" and then "ant" before running the application.
Jérôme Jaglale
Feb 19, 2009
#11
Thanks Jerome, I got it.
shruthi
Feb 20, 2009
#12
I am getting the below error:- java.lang.StackOverflowError javax.servlet.ServletException.getRootCause(ServletException.java:96) org.springframework.web.util.NestedServletException.getCause(NestedServletException.java:69) javax.servlet.ServletException.getRootCause(ServletException.java:96)

Apr 20, 2009
#13
Hi, I am getting the below error:- java.lang.StackOverflowError javax.servlet.ServletException.getRootCause(ServletException.java:96) org.springframework.web.util.NestedServletException.getCause(NestedServletException.java:69) javax.servlet.ServletException.getRootCause(ServletException.java:96) Everything was working fine till MVC tutorial but I am not able to complete the form processing. Thanks
Anuj
Apr 20, 2009
#14
Hi Anuj, have you tried to restart Tomcat?
Jérôme Jaglale
Apr 20, 2009
#15
Yes. I restarted tomcat and also deleted the work dir, but the same result. BTW I am not using the ant script. I am deploying it as a tomcat project in eclipse but I think this should not make any diff.
Anuj
Apr 20, 2009
#16
I don't know, then. It's the first time someone reports that. That must be something in your configuration. Let us know if you manage to fix it.
Jérôme Jaglale
Apr 20, 2009
#17
I was able to solve the problem. The issue was that the build path in eclipse were pointing to spring 2.5 version but the lib directory of my project had spring 3.0 jars. I just replaced the 3.0 jars with 2.5 and it worked fine.
Anuj
Apr 21, 2009
#18
Great! Thank you Anuj.
Jérôme Jaglale
Apr 21, 2009
#19
hi on calling this page i am geeting following error .please help me i am new in spring Error 500--Internal Server Error java.lang.NoSuchMethodError: org.springframework.web.util.WebUtils.getDefaultHtmlEscape(Ljavax/servlet/ServletContext;)Ljava/lang/Boolean; at org.springframework.web.servlet.support.RequestContext.initContext(RequestContext.java:215) at org.springframework.web.servlet.support.JspAwareRequestContext.initContext(JspAwareRequestContext.java:76) at org.springframework.web.servlet.support.JspAwareRequestContext.(JspAwareRequestContext.java:50) at org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:74) at jsp_servlet._web_45_inf._jsp.__carnew._jspService(__carnew.java:131) at weblogic.servlet.jsp.JspBase.service(JspBase.java:34) at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:226) at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:124) at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:283) at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:175) at weblogic.servlet.internal.RequestDispatcherImpl.invokeServlet(RequestDispatcherImpl.java:503) at weblogic.servlet.internal.RequestDispatcherImpl.forward(RequestDispatcherImpl.java:245) at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:171) at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:251) at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1160) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:901) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:809) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:476) at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:431) at javax.servlet.http.HttpServlet.service(HttpServlet.java:707) at javax.servlet.http.HttpServlet.service(HttpServlet.java:820) at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:226) at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:124) at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:283) at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:175) at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3370) at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321) at weblogic.security.service.SecurityManager.runAs(Unknown Source) at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2117) at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2023) at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1359) at weblogic.work.ExecuteThread.execute(ExecuteThread.java:200) at weblogic.work.ExecuteThread.run(ExecuteThread.java:172)
sumadha
Apr 24, 2009
#20
ya it was my silly mistake (due to first time in spring ).i solved this problem. sumadha.omar@gmail.com
sumadha
Apr 27, 2009
#21
very nice tutorial and easy to understand. Please add more examples.
SR
Jul 8, 2009
#22
Hi its giving me error at binder.setDisallowedFields
swaroop
Jul 8, 2009
#23
hi Jerome.. i need to add a hyperlink on my page which should invoke Spring MVC controller ( something like "Forgot Password" link ), Could you tell me how to do that ?
Neha
Jul 23, 2009
#24
This is one of the tutorials which would get you started with spring MVC. Its pretty easy to understand and can get some basic idea about the features in spring mvc and the way its been done in spring.Much appreciated
Kumar
Aug 4, 2009
#25
I get this error whenever I click submit button. can someone please help? thanks! org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.NullPointerException root cause java.lang.NullPointerException
me82
Aug 13, 2009
#26
These codes are not working in my implementation. do i still need to initialize something?
qwerty
Aug 13, 2009
#27
I'd just like to add my thanks to the others; this is a great introduction - it is priceless and has saved me countless hours of hand-wringing and lost-sleep. Regards and God bless.
Lanre
Aug 26, 2009
#28
Nice Article for beginners and very easy to understand and implement and thanks to the Author - VJ

Sep 1, 2009
#29
Nice Article for beginners and very easy to understand and implement and thanks to the Author
VJ
Sep 1, 2009
#30
Best tutorial for me
Yothin
Sep 9, 2009
#31
Tutorial useful thus far, thanks! I'm using Netbeans 6.7.1 with Spring Web MVC 2.5. Not my first tutorial but helping me to solidify things I didn't really get on previous tutorials. Hope to tame the Spring beast soon... :) Thanks again!
PUK
Sep 9, 2009
#32
Why are we creating Car out of Car in method createCar(Car car) ?
Makatun
Sep 16, 2009
#33
Gr8 deal
Ashutosh
Oct 6, 2009
#34
nice one keep it up
amol
Oct 14, 2009
#35
Thank you!
Trail
Oct 17, 2009
#36
Very good... please add some examples for DAO & Transaction Management .....
Korea
Oct 30, 2009
#37
This sentence needs work: initBinder: prevent Spring to do some bindings and so them by ourselves if needed. Here we used the brand id parameter to set the actual Brand.
Sambo
Nov 16, 2009
#38
OH thank you so much!! I've been trying to find a tutorial on working with collections and the select tag and have had no joy for almost a week. Most of the ones I found were either too cumbersome or not well written. I stumbled across this tutorial and its just perfect. Simple explanation with a simple code to get one started. Absolutely brilliant. Keep up the good work
quophyie
Nov 23, 2009
#39
Thank you. Very nice tutorial. But my onSubmit() function doesn't work. Please help me
deegii
Nov 27, 2009
#40
please : i java.lang.IllegalStateException: No WebApplicationContext found: no ContextLoaderListener registered? at org.springframework.web.servlet.support.RequestContextUtils.getWebApplicationContext(RequestContextUtils.java:84) at org.springframework.web.servlet.support.RequestContext.initContext(RequestContext.java:217) at org.springframework.web.servlet.support.JspAwareRequestContext.initContext(JspAwareRequestContext.java:75) at org.springframework.web.servlet.support.JspAwareRequestContext.(JspAwareRequestContext.java:49) at org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:74) at org.apache.jsp.new_005fcar_jsp._jspx_meth_form_form_0(new_005fcar_jsp.java from :102) at org.apache.jsp.new_005fcar_jsp._jspService(new_005fcar_jsp.java from :74) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:109) at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:389) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:486) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:380) at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:427) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:315) at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:287) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:218) at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:648) at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:593) at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:94) at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:98) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:222) at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:648) at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:593) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:587) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1096) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:166) at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:648) at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:593) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:587) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1096) at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:288) at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.invokeAdapter(DefaultProcessorTask.java:647) at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.doProcess(DefaultProcessorTask.java:579) at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.process(DefaultProcessorTask.java:831) at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.executeProcessorTask(DefaultReadTask.java:341) at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:263) at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:214) at com.sun.enterprise.web.portunif.PortUnificationPipeline$PUTask.doTask(PortUnificationPipeline.java:380) at com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:265) at com.sun.enterprise.web.connector.grizzly.ssl.SSLWorkerThread.run(SSLWorkerThread.java:106) StandardWrapperValve[jsp]: PWC1406: Servlet.service() for servlet jsp threw exception java.lang.IllegalStateException: No WebApplicationContext found: no ContextLoaderListener registered? at org.springframework.web.servlet.support.RequestContextUtils.getWebApplicationContext(RequestContextUtils.java:84) at org.springframework.web.servlet.support.RequestContext.initContext(RequestContext.java:217) at org.springframework.web.servlet.support.JspAwareRequestContext.initContext(JspAwareRequestContext.java:75) at org.springframework.web.servlet.support.JspAwareRequestContext.(JspAwareRequestContext.java:49) at org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:74) at org.apache.jsp.new_005fcar_jsp._jspx_meth_form_form_0(new_005fcar_jsp.java from :102) at org.apache.jsp.new_005fcar_jsp._jspService(new_005fcar_jsp.java from :74) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:109) at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:389) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:486) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:380) at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:427) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:315) at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:287) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:218) at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:648) at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:593) at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:94) at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:98) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:222) at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:648) at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:593) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:587) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1096) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:166) at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:648) at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:593) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:587) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1096) at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:288) at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.invokeAdapter(DefaultProcessorTask.java:647) at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.doProcess(DefaultProcessorTask.java:579) at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.process(DefaultProcessorTask.java:831) at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.executeProcessorTask(DefaultReadTask.java:341) at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:263) at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:214) at com.sun.enterprise.web.portunif.PortUnificationPipeline$PUTask.doTask(PortUnificationPipeline.java:380) at com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:265) at com.sun.enterprise.web.connector.grizzly.ssl.SSLWorkerThread.run(SSLWorkerThread.java:106)
Giorgi Archvadze from Georgia (Country), Tbilisi
Dec 9, 2009
#41
Very good tuorial for beginner
Giorgi Archvadze from Georgia (Country), Tbilisi
Dec 9, 2009
#42
Very nice tutorial..

Dec 29, 2009
#43
I'm trying to run these samples but I get this exception, any ideas? org.apache.jasper.JasperException: An exception occurred processing JSP page /jsp/carNew.jsp at line 11 8: <form:form method="post"> 9: 10: Brand
11: <form:select path="brand"> 12: <form:options items="${brandList}" itemLabel="name" itemValue="id" /> 13: </form:select> 14:

Stacktrace: org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:505) ... root cause java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'command' available as request attribute org.springframework.web.servlet.support.BindStatus.(BindStatus.java:141)...
albemuth
Jan 7, 2010
#44
I tried the example with little more additions. It worked. Its a nice example.It gave more clear understanding of spring mvc.Thanks a ton.
Swati
Jan 11, 2010
#45
Hi, Thanks for this tut. I had to add a permission to /etc/tomcat5.5/policy.d/04webapps.policy on my debian etch machine. It was : grant codeBase "file:/projects/java/spikes/springmvc/-" { permission java.lang.RuntimePermission "getClassLoader"; };
Anders Thøgersen
Jan 19, 2010
#46
I could not achieve this as stated by someone above: "I found the answer, if we bind the object on formBackingObject, it will automatically showing the value in db as selected."

Can someone please help by illustrating this?
TechS
Mar 2, 2010
#47
hi,

Can you explain about these tag

<property name="commandClass" value="com.springmvc.model.Car"/>
<property name="formView" value="carNew"></property>
<property name="successView" value="new_car.htm"></property>

and class from CarNewController, when call these method
formBackingObject, referenceData, initBinder

thanks & regards,
Venkatesan
Venkatesan
Mar 9, 2010
#48
Hi Jerome,

Thanks for putting this tutorial on the web. It is really helpful in understanding Spring MVC for a beginner.

Thanks a million
regards
Ramesh ( India )
Mar 19, 2010
#49
First of all, thanks a lot for your work.
My questions are:
1. springmv-servlet.xml is not defined in web.xml. So how the application refers to this file?

2. in initBinder(), brandId is obtained as below:
brandId = Long.parseLong(request.getParameter("brand"));
Here request.getParameter("brand") would return Mercedes.
then brandId would be what?

Can you hep?
Larry
Mar 24, 2010
#50
Larry,

1. Spring servlet is declared in web.xml. It knows about springmvc-servlet.xml.

2. The request parameter "brand" contains the brand id: in the JSP, for the "brand" select:
itemValue="id"
Jérôme Jaglale
Mar 24, 2010
#51
Hi Jérôme,
I got 2. cleared

For 1, so how should I name it? I believe there should be a rule to name the spring config file. Am I right or wrong?

Thanks a lot
Larry

Mar 25, 2010
#52
Larry,

Sorry, you're right, I had forgotten about it.

The Spring servlet's name in web.xml determines its config file's name. Example: if the servlet name is springmvc, the config file must be named springmvc-servlet.xml. If it was foo, it would be foo-servlet.xml.

More details there.
Jérôme Jaglale
Mar 25, 2010
#53
Hello sir,

I am new for spring framework but your tutorial teached me as a good teacher.
Thank's a lot.
shankar
Mar 26, 2010
#54
Hi Jérôme,
Thanks. I got to that page searching for the answer as well.

Overall, I have some experience in Struts, so I see Spring MVC very similar, and easy to understand. I still haven' seen the big advantage of Spring MVC over struts, to be honest.

But your work is helpful to a lot of people, including me. We all appreciate your kindness.

Larry
Larry
Mar 26, 2010
#55
Hi Jérôme,

Thanks for putting up this nice tutorial on the Web.

I'm having problem with this statment in initBinder method:

Long brandID = null;
...
brandId = Long.parseLong(request.getParameter("brand"));

I got error for: Type mismatch: cannot convert from long to Long

Thanks for your help in advance.


What did I do wrong in here?
Jin
Apr 3, 2010
#56
Hi, I have a .jsp page only with 3 text fields but none of them appear when I run the application!! The only way they appear is putting &lt;input type="text" name="xxx"/&gt; instead of &lt;form:input path="xxx"/&gt; How can I make it work? I mean I want to use &lt;form:input path="xxx"/&gt; in order to use the validators later. Please help. Thank you
Agustin
Apr 10, 2010
#57
simple and nice. good if explained its methods deeply with more examples
vamsi
Apr 12, 2010
#58
oh my god ,thats a lot of effort,It can be done in a thrice using servlets ,exactly the same thing .

Robert Harvey
Apr 28, 2010
#59
Great tutorial!
Draxa
May 9, 2010
#60
Basic and helpfull for me!
loga
May 19, 2010
#61

May 24, 2010
#62
bla bla
raghu
May 25, 2010
#63
Easy to understand. Very good, fast tutorial. Thanks.
Samar
Jun 7, 2010
#64
so simple and clear to understand
keep it up man !!
alan max
Jun 15, 2010
#65
Thanks This is really good.
John
Jun 20, 2010
#66
cool cool cool
Guru
Jul 16, 2010
#67
Good and very easy example,which makes the clear concept.
Thank you lot, how ever has written this.
rak
Jul 23, 2010
#68
Neat, thanks!
Patt
Aug 3, 2010
#69
GOOD BUT NEED GOOD EXAMPLES IN STEP WAYS
KALAIVANI
Aug 10, 2010
#70
The tutorial is truly excellent, but I do have one remark concerning your comment about Struts. Struts does the POJO binding/mapping with OGNL easier (even for complex objects) and with less effort on the developer side.

Aug 19, 2010
#71
very good and user friendly...thanks a ton
santhosh
Sep 7, 2010
#72
Thanks...a Lot
jittu
Sep 18, 2010
#73
SEVERE: Neither BindingResult nor plain target object for bean name 'carManager' available as request attribute
java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'carManager' available as request attribute
at org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:142)
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getBindStatus(AbstractDataBoundFormElementTag.java:176)
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getPropertyPath(AbstractDataBoundFormElementTag.java:196)
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getName(AbstractDataBoundFormElementTag.java:147)
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.autogenerateId(AbstractDataBoundFormElementTag.java:134)
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.writeDefaultAttributes(AbstractDataBoundFormElementTag.java:123)
at org.springframework.web.servlet.tags.form.AbstractHtmlElementTag.writeDefaultAttributes(AbstractHtmlElementTag.java:379)
at org.springframework.web.servlet.tags.form.SelectTag.writeTagContent(SelectTag.java:198)
at org.springframework.web.servlet.tags.form.AbstractFormTag.doStartTagInternal(AbstractFormTag.java:90)
at org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:77)
at org.apache.jsp.jsp.carNew_jsp._jspx_meth_form_005fselect_005f0(carNew_jsp.java:155)
at org.apache.jsp.jsp.carNew_jsp._jspx_meth_form_005fform_005f0(carNew_jsp.java:105)
at org.apache.jsp.jsp.carNew_jsp._jspService(carNew_jsp.java:69)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:328)
at org.apache.jasper.servlet.JspServlet.serviceJspFile&#40;JspServlet.java:315&#41;
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:210)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:685)
at java.lang.Thread.run(Unknown Source)
Sep 27, 2010 4:03:52 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet jsp threw exception
java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'carManager' available as request attribute
at org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:142)
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getBindStatus(AbstractDataBoundFormElementTag.java:176)
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getPropertyPath(AbstractDataBoundFormElementTag.java:196)
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getName(AbstractDataBoundFormElementTag.java:147)
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.autogenerateId(AbstractDataBoundFormElementTag.java:134)
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.writeDefaultAttributes(AbstractDataBoundFormElementTag.java:123)
at org.springframework.web.servlet.tags.form.AbstractHtmlElementTag.writeDefaultAttributes(AbstractHtmlElementTag.java:379)
at org.springframework.web.servlet.tags.form.SelectTag.writeTagContent(SelectTag.java:198)
at org.springframework.web.servlet.tags.form.AbstractFormTag.doStartTagInternal(AbstractFormTag.java:90)
at org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:77)
at org.apache.jsp.jsp.carNew_jsp._jspx_meth_form_005fselect_005f0(carNew_jsp.java:155)
at org.apache.jsp.jsp.carNew_jsp._jspx_meth_form_005fform_005f0(carNew_jsp.java:105)
at org.apache.jsp.jsp.carNew_jsp._jspService(carNew_jsp.java:69)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:328)
at org.apache.jasper.servlet.JspServlet.serviceJspFile&#40;JspServlet.java:315&#41;
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:210)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:685)
at java.lang.Thread.run(Unknown Source)
Shiva
Sep 27, 2010
#74
I'm trying to run these samples but I get this exception, any ideas

SEVERE: Neither BindingResult nor plain target object for bean name 'carManager' available as request attribute
java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'carManager' available as request attribute
at org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:142)
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getBindStatus(AbstractDataBoundFormElementTag.java:176)
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getPropertyPath(AbstractDataBoundFormElementTag.java:196)
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getName(AbstractDataBoundFormElementTag.java:147)
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.autogenerateId(AbstractDataBoundFormElementTag.java:134)
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.writeDefaultAttributes(AbstractDataBoundFormElementTag.java:123)
at org.springframework.web.servlet.tags.form.AbstractHtmlElementTag.writeDefaultAttributes(AbstractHtmlElementTag.java:379)
at org.springframework.web.servlet.tags.form.SelectTag.writeTagContent(SelectTag.java:198)
at org.springframework.web.servlet.tags.form.AbstractFormTag.doStartTagInternal(AbstractFormTag.java:90)
at org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:77)
at org.apache.jsp.jsp.carNew_jsp._jspx_meth_form_005fselect_005f0(carNew_jsp.java:155)
at org.apache.jsp.jsp.carNew_jsp._jspx_meth_form_005fform_005f0(carNew_jsp.java:105)
at org.apache.jsp.jsp.carNew_jsp._jspService(carNew_jsp.java:69)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:328)
at org.apache.jasper.servlet.JspServlet.serviceJspFile&#40;JspServlet.java:315&#41;
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:210)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:685)
at java.lang.Thread.run(Unknown Source)
Sep 27, 2010 4:03:52 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet jsp threw exception
java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'carManager' available as request attribute
at org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:142)
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getBindStatus(AbstractDataBoundFormElementTag.java:176)
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getPropertyPath(AbstractDataBoundFormElementTag.java:196)
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getName(AbstractDataBoundFormElementTag.java:147)
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.autogenerateId(AbstractDataBoundFormElementTag.java:134)
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.writeDefaultAttributes(AbstractDataBoundFormElementTag.java:123)
at org.springframework.web.servlet.tags.form.AbstractHtmlElementTag.writeDefaultAttributes(AbstractHtmlElementTag.java:379)
at org.springframework.web.servlet.tags.form.SelectTag.writeTagContent(SelectTag.java:198)
at org.springframework.web.servlet.tags.form.AbstractFormTag.doStartTagInternal(AbstractFormTag.java:90)
at org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:77)
at org.apache.jsp.jsp.carNew_jsp._jspx_meth_form_005fselect_005f0(carNew_jsp.java:155)
at org.apache.jsp.jsp.carNew_jsp._jspx_meth_form_005fform_005f0(carNew_jsp.java:105)
at org.apache.jsp.jsp.carNew_jsp._jspService(carNew_jsp.java:69)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:328)
at org.apache.jasper.servlet.JspServlet.serviceJspFile&#40;JspServlet.java:315&#41;
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:210)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:685)
at java.lang.Thread.run(Unknown Source)
Shiva
Sep 27, 2010
#75
Mind Blowing !!!
CHETAN
Oct 6, 2010
#76
Good tutorial!
But suppose that you have to delete a car.
In the hipotetic carDelete.jsp we need a &lt;form:select&gt; to show the list of the model.
And in the CarDeleteController.java how will the function initBinder?
Master Cifu
Oct 14, 2010
#77
Good tutorial!
What is we have 2 forms in same jsp page? Which one will be used? Can we define in spring xml which form should be used?

Rgds,
M
Marco
Oct 21, 2010
#78
I get error like this:
org.apache.jasper.JasperException: /jsp/carNew.jsp(12,3) Attribute itemLable invalid for tag options according to TLD
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:236)
org.apache.jasper.compiler.Validator$ValidateVisitor.checkXmlAttributes(Validator.java:1259)
org.apache.jasper.compiler.Validator$ValidateVisitor.visit(Validator.java:870)
org.apache.jasper.compiler.Node$CustomTag.accept(Node.java:1539)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2376)
org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2428)
org.apache.jasper.compiler.Validator$ValidateVisitor.visit(Validator.java:889)
org.apache.jasper.compiler.Node$CustomTag.accept(Node.java:1539)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2376)
org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2428)
org.apache.jasper.compiler.Validator$ValidateVisitor.visit(Validator.java:889)
org.apache.jasper.compiler.Node$CustomTag.accept(Node.java:1539)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2376)
org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2428)
org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2434)
org.apache.jasper.compiler.Node$Root.accept(Node.java:475)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2376)
org.apache.jasper.compiler.Validator.validateExDirectives(Validator.java:1789)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:216)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:365)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:345)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:332)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:594)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:327)
org.apache.jasper.servlet.JspServlet.serviceJspFile&#40;JspServlet.java:363&#41;
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:306)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:240)
org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:252)
org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1173)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:901)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:809)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:571)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:501)
javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
baboons
Nov 3, 2010
#79
I am a php developer, and looking into java, but I have to ask, why in the world would you want to do all of this to process a simple form, something that would take 10 minutes to build in php? I really would like to know. We are learning mvc with php, and it too takes way too much to do simple tasks. Can someone please tell me the benefit? Thanks
Jerry Lee
Nov 4, 2010
#80
Is this still valid in 3.x? I'm new, but this example feels like it's 2.5 oriented. It would be great if you would call out the Spring version it's based on.
David Parks
Nov 6, 2010
#81
Using simpleformController how can we setup for many actions?as example single controller can we use to perform add/delete/modify of a student record or we need separate controller for each and every action i am referring spring 2.5 simpleformcontroller without annotations
jarwins
Nov 8, 2010
#82
thanks
rajendra
Dec 21, 2010
#83
Hi

this looks nice but when i deploy it to my tomcat and call the new_car.html, it says resource unavailable

I tried modelling my own project following the steps (only with a different class instead of car)

The problem is that it never shows me the form, it takes me straight to successview :( what could be wrong?
Tanya
Dec 28, 2010
#84
very usefull
niranjan
May 22, 2011
#85
This is probably the best MVC tutorial ever. Great job !!!
MIka
May 31, 2011
#86
Great Work. Finally a tutorial that can be followed clearly.
Justin Case
May 31, 2011
#87
Nice ONE.
chandu
Jun 28, 2011
#88
I am not able to run this program in sts .could someone help me.

thanks in advance
madhu
Jun 28, 2011
#89
Good work with Nice examples
Naresh
Jun 30, 2011
#90
Good examples. Well Done. Thanks. Was easily understandable. Maybe a better explanation of the various spring classes involved would be helpful.
Raj
Jul 5, 2011
#91
Good Example
Amit
Aug 2, 2011
#92
you can become the co author for the book

Head first Spring
ravi
Oct 25, 2011
#93
"co-author" of a book? Hell no. Dude do you seriously test your examples before posting it online? Every single one of your examples has critical errors which prevent it from working.
Disappointed user
Nov 3, 2011
#94
really good job buddy !! its crisp and clear :) thanks
surya
Dec 5, 2011
#95
@Disappointed user.. u will be Disappointed always..
siddharth
Jan 31, 2012
#96
great job - thank you for all your work - if you have a sec - where do the request values get turned into a car? somewhere in the background of initBinder?

thanks again!
happy user
Feb 2, 2012
#97
I am able to complete tutorials nicely. Thanks. One issue I had was not able to compile JSP due to JSTL tag lib error because I am using tomcat 6. Below URL was helpful (incase someone has similar issue)
http://www.mularien.com/blog/2008/02/19/tutorial-how-to-set-up-tomcat-6-to-work-with-jstl-12/

I am coming from another application server; so form processing here is little different but after adding few debugs in the code .. makes sense.
VR
Feb 4, 2012
#98
GOOD ONE
ABC
Mar 22, 2012
#99
Hi, great tutorial for beginning Spring MVC candidates. I got this far and also Spring dependency Injection works, but get this error when I try the SimpleFormController and form submission:
The url is written correctly and called correctly.

WARNING: No mapping found for HTTP request with URI [/SpringMvc/newCar.htm] in DispatcherServlet with name 'dispatcher'
Uma
Aug 1, 2012
#100
This is the bean configuration for above posting

<bean name="/newCar.htm" class="web.CarNewController">
<property name="carManager" ref="carManager"/>
<property name="commandClass" value="model.Car"></property>
<property name="formView" value="car-new"></property>
<property name="successView" value="carlist.htm"></property>
</bean>
Uma
Aug 1, 2012
#101
This is the first time I am trying Spring. I see Spring 3 is out but your explanations are wonderful. And now in 2012 this is still so useful in understanding Spring. Thanks for sharing this.
SS
Aug 3, 2012
#102
Thank you so much!!! better than any other books

Hyeongseok
Aug 16, 2012
#103
nice example. good example
Shabeer Ali
Jul 30, 2014
#104