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>