SpringMVC's HelloWord, springmvchelloword

Source: Internet
Author: User

SpringMVC's HelloWord, springmvchelloword
SpringMVC (helloWord)1. Import jar package 2. Create xml files for spring and springMVC 3. configure the listener and core servlet and location of spring in xml. The following describes in detail each step 1. Create a web project demoapp2, import spring jar 3 under web-INF/lib, and spring xml, you only need to write a helloword, you only need to configure a scan package (spring-config.xml? Xml version = "1.0" encoding = "UTF-8"?> <Beans xmlns = "http://www.springframework.org/schema/beans" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xmlns: aop = "http://www.springframework.org/schema/aop" xmlns: tx = "http://www.springframework.org/schema/tx" xmlns: context = "http://www.springframework.org/schema/context" xmlns: task = "http://www.springframework.org/schema/task" xmlns: dwr = "http://www.directwebremoting.org/schema/spring-dwr" x Si: schemaLocation = "http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsd http://www.springframework.org/schema/context http://www.springframe Work.org/schema/context/spring-context-4.1.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.1.xsd "> <! -- Configure the scan package --> <context: annotation-config/> <context: component-scan base-package = "com. demo"/> <! -- </Beans>4. Manage springmvc xml (application. xml)<Beans xmlns = "http://www.springframework.org/schema/beans" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xmlns: p = "http://www.springframework.org/schema/p" xmlns: context = "http://www.springframework.org/schema/context" xmlns: util = "http://www.springframework.org/schema/util" xmlns: mvc = "http://www.springframework.org/schema/mvc" xmlns: oxm = "http://www.springframework.org/schema/oxm" xsi: schemaLo Http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.1.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd http://www.springframework.org/schema/mvc http://www.springfr Amework.org/schema/mvc/spring-mvc-4.1.xsd http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm.xsd "> <! -- Scan package --> <context: component-scan base-package = "com. demo. **. controller "> <context: include-filter type =" annotation "expression =" org. springframework. stereotype. controller "/> </context: component-scan> <! -- Default view parser --> <bean class = "org. springframework. web. servlet. view. internalResourceViewResolver "> <property name =" prefix "value ="/WEB-INF/jsp/"/> <property name =" suffix "value = ". jsp "/> </bean> </beans> 3. configure spring in xml <! -- Spring configuration file start --> <context-param> <param-name> contextConfigLocation </param-name> <param-value> classpath: spring -*. xml </param-value> <! -- <Param-value> classpath: spring-config.xml; classpath: spring-redis.xml; </param-value> --> </context-param> <listener-class> org. springframework. web. context. contextLoaderListener </listener-class> </listener> <servlet-name> spring </servlet-name> <servlet-class> org. springframework. web. servlet. dispatcherServlet </servlet-class> <init-param> <param-name> contextConfigLocation </param-nam E> <param-value> classpath: application. xml </param-value> </init-param> </servlet> <servlet-mapping> <servlet-name> spring </servlet-name> <url-pattern>/ </url-pattern> </servlet-mapping> <! -- Spring configuration file end --> spring listener ---> context | LoaderListener, core servlet --> dispatcherServlet 5. Create a class, TestController, add @ requestMapping ("path") to the corresponding method and create it under the controller package. scan package @ Controllerpublic class TestController {@ RequestMapping ("/hello") public String hello () {System. out. println ("hello this is hello method"); return "hello ";}}

 

6. Use the corresponding path on the page. <a href = "<% = path %>/hello"> hello springMVC </a> SpringMVC (helloWord)1. Import jar package 2. Create xml files for spring and springMVC 3. configure the listener and core servlet and location of spring in xml. The following describes in detail each step 1. Create a web project demoapp2, import spring jar 3 under web-INF/lib, and spring xml, you only need to write a helloword, you only need to configure a scan package (spring-config.xml? Xml version = "1.0" encoding = "UTF-8"?> <Beans xmlns = "http://www.springframework.org/schema/beans" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xmlns: aop = "http://www.springframework.org/schema/aop" xmlns: tx = "http://www.springframework.org/schema/tx" xmlns: context = "http://www.springframework.org/schema/context" xmlns: task = "http://www.springframework.org/schema/task" xmlns: dwr = "http://www.directwebremoting.org/schema/spring-dwr" x Si: schemaLocation = "http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsd http://www.springframework.org/schema/context http://www.springframe Work.org/schema/context/spring-context-4.1.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.1.xsd "> <! -- Configure the scan package --> <context: annotation-config/> <context: component-scan base-package = "com. demo"/> <! -- </Beans> 4. Manage springmvc xml (application. xml)<Beans xmlns = "http://www.springframework.org/schema/beans" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xmlns: p = "http://www.springframework.org/schema/p" xmlns: context = "http://www.springframework.org/schema/context" xmlns: util = "http://www.springframework.org/schema/util" xmlns: mvc = "http://www.springframework.org/schema/mvc" xmlns: oxm = "http://www.springframework.org/schema/oxm" xsi: schemaLo Http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.1.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd http://www.springframework.org/schema/mvc http://www.springfr Amework.org/schema/mvc/spring-mvc-4.1.xsd http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm.xsd "> <! -- Scan package --> <context: component-scan base-package = "com. demo. **. controller "> <context: include-filter type =" annotation "expression =" org. springframework. stereotype. controller "/> </context: component-scan> <! -- Default view parser --> <bean class = "org. springframework. web. servlet. view. internalResourceViewResolver "> <property name =" prefix "value ="/WEB-INF/jsp/"/> <property name =" suffix "value = ". jsp "/> </bean> </beans> 3. configure spring in xml <! -- Spring configuration file start --> <context-param> <param-name> contextConfigLocation </param-name> <param-value> classpath: spring -*. xml </param-value> <! -- <Param-value> classpath: spring-config.xml; classpath: spring-redis.xml; </param-value> --> </context-param> <listener-class> org. springframework. web. context. contextLoaderListener </listener-class> </listener> <servlet-name> spring </servlet-name> <servlet-class> org. springframework. web. servlet. dispatcherServlet </servlet-class> <init-param> <param-name> contextConfigLocation </param-nam E> <param-value> classpath: application. xml </param-value> </init-param> </servlet> <servlet-mapping> <servlet-name> spring </servlet-name> <url-pattern>/ </url-pattern> </servlet-mapping> <! -- Spring configuration file end --> spring listener ---> context | LoaderListener, core servlet --> dispatcherServlet 5. Create a class, TestController, add @ requestMapping ("path") to the corresponding method and create it under the controller package. scan package @ Controllerpublic class TestController {@ RequestMapping ("/hello") public String hello () {System. out. println ("hello this is hello method"); return "hello ";}} 6. Use the corresponding path on the page. <a href = "<% = path %>/hello"> hello springMVC </a>

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.