Spring MVC Annotation Version Environment build process-note You don't need to configure the two irrelevant

Source: Internet
Author: User
Tags xmlns
Build the spring MVC process

Directory structure:


Process is as follows

1 jar packages that need to be imported with SPRINGMVC

2 in Web.xml need to add the following configuration

<servlet>
        <servlet-name>golfing</servlet-name>
                    <servlet-class> Org.springframework.web.servlet.dispatcherservlet</servlet-class>
        <load-on-startup>1</ load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>golfing</ servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

3 config file under Web-inf

<?xml version= "1.0" encoding= "UTF-8"?> <beans "xmlns=" xmlns: Mvc=http://www.springframework.org/schema/mvc xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xmlns: context= "Http://www.springframework.org/schema/context" xsi:schemalocation= "http://www.springframework.org/s Chema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework. ORG/SCHEMA/MVC http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd HTTP://WWW.SPRINGFRAMEWORK.O Rg/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd "> <mvc:annotat Ion-driven/> <context:component-scan base-package= "Com.sm.nothing.controller"/> <!--configuration View Parser
    ; <bean class= "Org.springframework.web.servlet.view.InternalResourceViewResolver" > <property name= "Viewcla" SS "Value=" Org.springframework.web.sErvlet.view.JstlView "/> <property name= prefix" value= "/web-inf/views/" ></property> &LT;PR
  Operty name= "suffix" value= ". jsp" ></property> </bean> <!--...--> </beans>


It turns out that completely <mvc:annotation-driven/> can get rid of


4 controller classes are as follows:

Package Com.sm.nothing.controller;
 
Import Org.springframework.stereotype.Controller;
Import org.springframework.web.bind.annotation.RequestMapping;
Import Org.springframework.web.servlet.ModelAndView;
@Controller public
class hellocontroller{
        
         @RequestMapping (value= "/index.html") public
         Modelandview Index () {
                  Modelandview Mav = new Modelandview ("Index", "MSG", "Springmvc, Hello world!");
                  return Mav
         }
}


the contents of web-inf/views/index.jsp in the 5 directory are:

<p>${msg}</p>

6 Execution Effect

Home map

Input path http://localhost:8080/springmvctest/index.html, page success jump

Download the address for the executable source code below

Http://www.kuaipan.cn/file/id_140422426734362790.htm

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.