SPRINGMVC's Helloword

Source: Internet
Author: User
Tags naming convention

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

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.