"Springmvc from Introduction to unbridled" I. Overview

Source: Internet
Author: User
Tags aop

I. Overview of SPRINGMVC

View Service Dao Db
Spring MVC Interface Interface Mysql
Impls Impls

SPRINGMVC is also called Spring Web MVC, which belongs to the presentation layer framework. SPRINGMVC is part of the spring framework and is released after Spring3.0.

Second, the first SPRINGMVC procedure
Function Description:
The user submits a request, and the server-side processor responds with a welcome message to the client after receiving the request.
New project:
Eclipse:file-->new-->web Project
To export a jar package:

Commons-logging-1.2.jarlog4j-1.2.17.jarspring-aop-4.3.9.release.jarspring-aspects-4.3.9.release.jarspring-beans-4.3.9.rel Ease.jarspring-context-4.3.9.release.jarspring-context-support-4.3.9.release.jarspring-core-4.3.9.release.jarspring-expre ssion-4.3.9.release.jarspring-jdbc-4.3.9.release.jarspring-orm-4.3.9.release.jarspring-tx-4.3.9.release.jarspring-web-4.3 .9.release.jarspring-webmvc-4.3.9.release.jar

New Package: Cn.wechatbao.controller
New class:

Package Cn.wechatbao.controller;import Javax.servlet.http.httpservletrequest;import Javax.servlet.http.httpservletresponse;import Org.springframework.web.servlet.modelandview;import org.springframework.web.servlet.mvc.controller;/*** to implement the Controller interface, this is even a SPRINGMVC controller. * @author Jonas**/public class Mycontroller implements Controller {    @Override public    Modelandview HandleRequest (HttpServletRequest request,        HttpServletResponse response) throws Exception {        Modelandview mv = new Modelandview ();        Mv.addobject ("message", "Hello Spring MVC World");        Mv.setviewname ("/web-inf/jsp/welcome.jsp");        return mv;    }}

  

Third, configuration Srpingmvc.xml
Create the Springmvc.xml file under src/and write the following:

<?XML version= "1.0" encoding= "UTF-8"?><Beansxmlns= "Http://www.springframework.org/schema/beans"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"Xmlns:context= "Http://www.springframework.org/schema/context"XMLNS:AOP= "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP"Xmlns:tx= "Http://www.springframework.org/schema/tx"xsi:schemalocation= "http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/ spring-beans.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/ spring-context.xsdhttp://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/ Spring-aop.xsdhttp://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx.xsd " ><!--registering the SPRINGMVC processor -    <BeanID= "/my.do"class= "Cn.wechatbao.controller.MyController"></Bean></Beans>

Note: The above import a lot of spring constraints, here actually only need to beans, because we are only learning Springmvc, some other temporarily still not used, but with the depth, will be used in the future, so here I will be the complete spring constraints are put up. To illustrate the specific role of each constraint.

1, spring-beans.xsd srping core constraints, mainly for the definition of beans, etc.
2. Spring-context.xsdspring context
3, spring-aop.xsdspring-oriented programming (section here does not explain, in the future encountered re-interpretation)
4, Spring-tx.xsdspring's declarative transaction

Iv. Registration of Central Scheduler
In Web-inf/web.xml, add the following:

<!--registering the Central scheduler -<servlet>    <Servlet-name>Springmvc</Servlet-name>    <Servlet-class>Org.springframework.web.servlet.DispatcherServlet</Servlet-class>    <!--Specify the location and file name of the SPRINGMVC configuration file -    <Init-param>        <Param-name>Contextconfiglocation</Param-name>        <Param-value>Classpath:springmvc.xml</Param-value>    </Init-param>    <!--The default Dispatcherservlet object is to create the object after the request is made, modify the number above the Load-on-startup to 0, which means that the Dispatcherservlet object is created directly when Tomcat starts, the smaller the number priority Higher (except 0) -    <Load-on-startup>1</Load-on-startup></servlet><servlet-mapping>    <Servlet-name>Springmvc</Servlet-name>    <Url-pattern>*.do</Url-pattern><!--It is recommended that you intercept specific suffixes -</servlet-mapping>

Note: If you do not configure Init-param, the configuration file will need to be in the Web-inf directory with the file name Servlet-name plus-servlet.xml. The specific source code can be found through the Dispatcherservlet class to find its parent class Org.springframework.web.servlet.FrameworkServlet, such as:


Five, test function
Once the above configuration is configured, the program can be published and run. After posting to Tomcat, everyone directly enters the processor my.do that we have configured in Springmvc.xml in the browser.
Http://localhost:8080/SpringMVC/my.do
This is true if the following interface appears:

"Springmvc from Introduction to unbridled" I. Overview

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.