Reputation: 8397
I have learned how to use Spring MVC 3, but I am very interested in background of it. One of the most interesting things to me is forms handling.
So far, I know that every http request in handled by dispatcher, mapped to proper controller. Controlles make some behind work, and than selects JSPX page to be loaded, and sends attributes to it. JSPX in compiled by container (Tomcat, etc...) to another servlet. Than web page is send back in http response.
This seems all right for me, in most case scenarios. But, form handling is different. In <form:form>
tag, you defined object and attributes mapping to it. But in logic mentioned above, it actually never gets invoked. I mean, user requests page with form. So controller renders it. Than user send form, and some save method is invoked by dispatcher. But how does Spring know how to map incomming attributes, if they are described in JSPX that is not invoked?
Also, if you know any good, preferably web, resource on Spring MVC background, post a link. Thank you.
Upvotes: 2
Views: 3746
Reputation: 3460
From the way you describe your question, I guess you know the concept of HTTP. However it seems that you don't know deep enough to differentiate HTTP parameter and request attribute and their life cycle.
When user request a page, a method within a Controller
is invoked and will return the View
to display along with the request attribute set from Controller
. The view is then rendered in HTML
format. Within this HTML
, there is a form that is rendered. This form has action that may or may not be pointing to the same URL. The URL is again, mapped to the Controller's method (could be the same Controller with different method or totally different Controller) when a request is sent back. Along with the second request, those parameters within the form, will be sent to the corresponding Controller's method and the same cycle happen again as the first one.
Upvotes: 1
Reputation: 18143
Well, the king of all Spring references is at
http://static.springsource.org/spring/docs/current/
There are long sections on the MVC, and on how to build pages using Spring tags.
The problem is, telling you to read that is like telling you to get a drink from a fire hose. As I have gotten better at using Spring, I've learned that knowing how to do one thing well in Spring means knowing how to do other things well with Spring.
It's all worth learning, and the real strengths of Spring reveal themselves as you learn more about it.
Googling for "example spring form" turns up useful examples like the one at http://www.mkyong.com/spring-mvc/spring-mvc-form-handling-example/ But the problem with this approach toward learning is that Spring is constantly evolving. I've found that learning from random examples on the web is complicated by the fact that some people posted their examples before Spring 3 was available, or befor annotations were available, and so on.
For me, as I continue to learn Spring, there has not been one reference. It's been the main reference, lots of examples on the web, and reading lots of questions here, and posting a few.
Upvotes: 4