Springmvc web novices to build simple process -caidachun

First time to do the whole day, among a variety of error, big brother will certainly have to laugh at me, but still a lot of achievements dare, now only know how to assemble, do not know why, but also need to learn, come on

1. Create a new dynamic web project

 

 

2. Add the jar package, can go online to download, commons-logs.jar I volunteered for

 

 

 3.web.xml configuration, classpath: springmvc.xml, specify initialization parameters springmvc load the file, you need to create a new springmvc.xml in src

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    id="WebApp_ID" version="3.0">
<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:springmvc.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> </web-app>

4. Configuration springmvc.xml, build a package com.springmvc. * Class must be established com.springmvc. * Under. Configuration will scan the page on the package path / WEB-INF / pages /

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:util="http://www.springframework.org/schema/util"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
       http://www.springframework.org/schema/context 
       http://www.springframework.org/schema/context/spring-context-3.0.xsd 
       http://www.springframework.org/schema/util 
       http://www.springframework.org/schema/util/spring- 3.0.xsd-util 
       http://www.springframework.org/schema/mvc 
       http://www.springframework.org/schema/mvc/spring-mvc.xsd 
      " > 

    <-! open comments mode driver -> 
    < MVC: Annotation-Driven > </ MVC: Annotation-Driven > 
    <-! sweep packet -> 
    < context: Scan-Component
         Base-package = "com.springmvc *." > </ context: Component-Scan > 
    <!- Static Resources filter-> 
    < MVC: Resources LOCATION = "/ Resources /" 
        Mapping = "/ Resources / **"  /> 


    ! <- view rendering JSP / FreeMaker / Velocity -> 
    < the bean
         class = "org.springframework.web. servlet.view.InternalResourceViewResolver " > 
        <-! path development page stored -> 
        < Property name =" prefix " value =" / the WEB-INF / pages and the / " > </ Property > 
        <-! the file extension - -> 
        < Property name = "suffix" value=".jsp"></property>
    </bean>

</beans>

 

Guess you like

Origin www.cnblogs.com/caidachun-didi/p/11539845.html