Spring Series, part 3rd: Entering Spring MVC

Source: Internet
Author: User

Spring MVC Framework

The Spring framework provides a full-featured MVC module for building WEB applications. Using spring's pluggable MVC architecture, you can choose to use a web framework such as the built-in Spring web framework or Struts. Through the policy interface, the Spring framework is highly configurable and contains a variety of view technologies, such as JavaServer Pages (JSP) technology, Velocity, Tiles, IText, and POI. The Spring MVC Framework does not know the views used, so you will not be forced to use only JSP technology. Spring MVC separates the roles of controllers, model objects, dispatchers, and handler objects, which makes them easier to customize.

The Spring Web MVC Framework is designed around Dispatcherservlet, which assigns requests to handlers with configurable handler mappings, view resolution, local language, topic resolution, and upload file support. The default handler is a very simple Controller interface, with only one method Modelandview HandleRequest (request, response). Spring provides a controller hierarchy that can derive subclasses. If your application needs to process user input forms, you can inherit Abstractformcontroller. If you need to process multiple-page input to a form, you can inherit Abstractwizardformcontroller.

The sample application helps to visually learn these features. The bank application allows users to retrieve their account information. In building a banking application, you can learn how to configure the Spring MVC framework and the view layer of the implementation framework, which includes JSTL tags (data for displaying output) and JavaServer Pages technology.

Configuring Spring MVC

To start building the sample application, configure the Dispatcherservlet for Spring MVC. Please register all configurations in the Web.xml file. Listing 1 shows how to configure the Samplebankingservlet.

Listing 1. Configuring the Spring MVC Dispatcherservlet

<servlet>
  <servlet-name>sampleBankingServlet</servlet-name>
  <servlet-class>
    org.springframework.we.servlet.DispatcherServlet
  <servlet-class>
  <load-on-startup>1<load-on-startup>
<servlet>

Dispatcherservlet is loaded from an XML file into the Spring application context, and the name of the XML file is followed by the name of the servlet plus-servlet. In this example, Dispatcherservlet loads the application context from the Samplebankingservlet-servlet.xml file.

Configure the URL of an application

The next step is to configure the URL that you want Samplebankingservlet to process. Again, register all of this information in the Web.xml.

Listing 2. Configure the URL you want to process

<servlet-mapping>
<servlet-name> sampleBankingServlet<servlet-name>
<url-pattern>*.jsp</url-pattern>
</servlet-mapping>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.