SPRINGMVC is an MVC framework that doesn't say concepts. This Baidu a big push.
Get ready:
1 The jar required by the SPRINGMVC. can be re-downloaded in the warehouse. or official website.
2 Create a Dynamic Web project. Put the prepared jar in Lib.
3 Configure the Springmvc Dispatcherservlet. Let Dispatcherservlet intercept all URL requests. Then dispatcherservlet resolves the URL to find the appropriate controller for the requestmapping. Implement the appropriate service methods
<!--configuring SPRINGMVC interceptors Dispatcherservlet- <servlet> <servlet-name>dispatcherservlet </servlet-name> <servlet-class>org.springframework.web.servlet.dispatcherservlet</ servlet-class> <load-on-startup>1</load-on-startup> </servlet> < servlet-mapping> <servlet-name>dispatcherServlet</servlet-name> <url-pattern>/ </url-pattern> </servlet-mapping>
All URL requests are like a service in the Client Access server. The address is then handed to dispatcherservlet for processing and forwarding to the appropriate service method, and corresponding to the client.
4 service code for server-side publishing
@Controllerpublic class Hello {@RequestMapping ("/sayhello") public String Say () {System.out.println ("url:http:// Localhost:8080/springmvc/sayhello "); return" Show ";} @RequestMapping ("/printhello") public String print () {System.out.println ("url:http://localhost:8080/springmvc/ Printhello "); return" Show ";}}
5 Create the Springmvc profile under Web-inf: The naming convention is: name<servlet-name>dispatcherservlet</for SPRINGMVC servlet registered in Web. xml Servlet-name> is dispatcherservlet-servlet.xml.
<!--Configuring a custom Scan package--><context:component-scan base-package= "Cn.bean.hello" ></context:component-scan> <!--configuration View resolver: How to resolve the handler method return value to the actual physical view--><bean class= " Org.springframework.web.servlet.view.InternalResourceViewResolver "><property name=" prefix "value="/web-inf /views/"></property><property name=" suffix "value=". JSP "></property></bean>
We can then release our well-written Controller via Tomcat. After Tomcat is started. Access Http://localhost:8080/springMVC/sayHello through the browser. You'll see the printed information in the console.
SPRINGMVC's Helloword