Establish SPRINGMVC Project

Source: Internet
Author: User

1. Configure Web. xml

<!--Configure Dispatcherservlet -    <servlet>        <Servlet-name>Dispatcherservlet</Servlet-name>        <Servlet-class>Org.springframework.web.servlet.DispatcherServlet</Servlet-class>                <!--Configure the initialization parameters of the Dispatcherservlet to configure the SPRINGMVCSpecify the location and name of the configuration file, or use the default:

Under the Web-inf, <servlet-name>-servlet.xml, such as the current can be: Dispatcherservlet-servlet.xml

 -        <Init-param>            <Param-name>Contextconfiglocation</Param-name>            <!--specifying the SPRINGMVC configuration file -            <Param-value>Classpath:springmvc.xml</Param-value>        </Init-param>         <!--indicates that it was created at the time of loading -        <Load-on-startup>1</Load-on-startup>    </servlet>        <servlet-mapping>        <Servlet-name>Dispatcherservlet</Servlet-name>        <!--reply to all requests -        <Url-pattern>/</Url-pattern>    </servlet-mapping>

2. Build the processor (Controller)

@Controller//specified as the request processor Public classHelloword {/*** 1. Use @RequestMapping annotations to map the requested URL * 2./HELLOWORLD Specifies the controller for the page request * 3. Success in return: by SPRINGM Vc.xml configuration of the internalresourceviewresolver resolution, the method is: * prefix + returnval + suffix way to forward to the specified page, this example is/web-inf/views /+ success +. JSP * Results are forwarded to/WEB-INF/VIEWS/SUCCESS.JSP * *@return      */@RequestMapping ("/helloworld")     PublicString Hello () {System.out.println ("Hello World"); return"Success"; }}

3. Create a new Springmvc.xml file (Eclipse installs the Spring IDE plugin)

Select beans, context, MVC entry

<!--Configuring the annotation scan package -    <Context:component-scanBase-package= "Com.handlers"></Context:component-scan>        <!--Configure the View resolver: that is, configure the Controller method to return to that page, the result is: Prefix + return value + suffix, -    <Beanclass= "Org.springframework.web.servlet.view.InternalResourceViewResolver">        < Propertyname= "prefix"value= "/web-inf/views/"></ Property>        < Propertyname= "suffix"value= ". jsp"></ Property>    </Bean>

5. Writing the request page

<href= "HelloWorld">Hello World</a> 

6. Normal access to the

Establish SPRINGMVC Project

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.