Springmvc__simpleurlhandlermapping (processing the access address in the form of a key-value pair)

Source: Internet
Author: User

1. Configure the Web. XML (here configuration Url-pattern/)

<!--Coded Filters -    <Filter>        <Filter-name>Characterencodingfilter</Filter-name>        <Filter-class>Org.springframework.web.filter.CharacterEncodingFilter</Filter-class>        <Init-param>            <!--Change the existing encoding method to -            <Param-name>Encoding</Param-name>            <Param-value>UTF-8</Param-value>        </Init-param>        <Init-param>            <!--Force use of this code in any case -            <Param-name>Forceencoding</Param-name>            <Param-value>True</Param-value>        </Init-param>    </Filter>    <filter-mapping>        <Filter-name>Characterencodingfilter</Filter-name>        <Url-pattern>/*</Url-pattern>    </filter-mapping>    <!--Central Scheduler -    <servlet>        <Servlet-name>Springmvc</Servlet-name>        <Servlet-class>Org.springframework.web.servlet.DispatcherServlet</Servlet-class>        <Init-param>            <Param-name>Contextconfiglocation</Param-name>            <Param-value>Classpath:applicationContext.xml</Param-value>        </Init-param>        <Load-on-startup>1</Load-on-startup>    </servlet>    <servlet-mapping>        <Servlet-name>Springmvc</Servlet-name>        <Url-pattern>/</Url-pattern>    </servlet-mapping>

2. Handling static resources in Applicationcontext.xml

<!---    < />

3. Configuring the Processor

 Public class extends Abstractcontroller {    @Override    public  Modelandview handlerequestinternal ( HttpServletRequest arg0,            throws  Exception {                new  Modelandview ();                Mv.addobject ("MSG", "model returned by the processor");        Mv.setviewname ("one");                 return mv;    }}

4. Registering the processor

 <!--  Register processor     -->  <  bean  id  = "Frist"   class  = "Cn.cnsdhzzl.controller.MyController"         >  <  property  name  = "Supportedmethods"   value  = "Get,post"  ></ property     >  </ bean  >  

5. Configure the Simpleurlhandlermapping settings access path

<!--using simpleurlhandlermapping -    <Beanclass= "Org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">        < Propertyname= "Mappings">            <Props>                <propKey= "/simple">Frist</prop>            </Props>        </ Property>    </Bean>

6. Access Address

Springmvc__simpleurlhandlermapping (processing the access address in the form of a key-value pair)

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.