Quick start to Spring MVC development

Source: Internet
Author: User

This article will teach you how to use the spring framework quickly, and if you have a spring in action on your hands, you'd better start with the third part of Spring's application in the Web layer-building the web layer, otherwise it would be a nightmare!

First, I need to build the basic concept of Spring MVC in your heart. When a spring-based WEB application receives a request for http://localhost:8080/hello.do (in fact, the request path is/hello.do), spring hands the request to a Hellocontroller Process, Hellocontroller calls a JSP file called hello.jsp to generate HTML code to the user's browser display. The name above (/hello.do,hellocontroller,hello.jsp) is a variable that you can change.

In Spring MVC, in the JSP file, try not to have Java code, only the HTML code and the "Iteration (ForEach)" and "Judgment (IF)" two jstl tags. The JSP file is used only as a rendering (or view) template.

All right, let's get started. First we need a web.xml file placed in the Web-inf directory:

web.xml: 1 <?xml version= "1.0" encoding= "UTF-8"?>


2


3 <web-app version= "2.4" xmlns= "HTTP://JAVA.SUN.COM/XML/NS/J2EE"


4 xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"


5 xsi:schemalocation= "Http://java.sun.com/xml/ns/j2ee


6 http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd ">


7


8 <context-param>


9 <param-name>contextConfigLocation</param-name>


<param-value>


11/web-inf/database.xml


12/web-inf/applicationcontext.xml


</param-value>


</context-param>


15


<listener>


<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>


</listener>


19


<filter>


<filter-name>encodingFilter</filter-name>


<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>


<init-param>


<param-name>encoding</param-name>


<param-value>UTF-8</param-value>


</init-param>


</filter>


28


<filter-mapping>


<filter-name>encodingFilter</filter-name>


<url-pattern>*.do</url-pattern>


</filter-mapping>


33


<servlet>


<servlet-name>ideawu</servlet-name>


<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>


Notoginseng <load-on-startup>1</load-on-startup>


</servlet>


39


<servlet-mapping>


<servlet-name>ideawu</servlet-name>


<url-pattern>*.do</url-pattern>


</servlet-mapping>


44


<welcome-file-list>


<welcome-file>index.jsp</welcome-file>


<welcome-file>index.html</welcome-file>


</welcome-file-list>


49


<jsp-config>


Wuyi <taglib>


<taglib-uri>http://java.sun.com/jsp/jstl/core</taglib-uri>


<taglib-location>/WEB-INF/tld/c.tld</taglib-location>


</taglib>


<taglib>


<taglib-uri>http://java.sun.com/jsp/jstl/fmt</taglib-uri>


<taglib-location>/WEB-INF/tld/fmt.tld</taglib-location>


</taglib>


</jsp-config>


60


</web-app>

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.