zoukankan      html  css  js  c++  java
  • Spring MVC开发初体验

    1.目标实现Spring MVC :
      Hello World!


    2.工程创建步骤

    new : Dynamic Web Project
      


    lib引入Spring框架libs/*.jar

    touch web.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app version="2.4" 
        xmlns="http://java.sun.com/xml/ns/j2ee" 
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
            http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
        <servlet>
            <servlet-name>springMVC</servlet-name>
                <servlet-class>
                    org.springframework.web.servlet.DispatcherServlet
                </servlet-class>
                <init-param>
                    <param-name>contextConfigLocation</param-name>
                    <param-value>/WEB-INF/config/springMVC-servlet.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>

    touch config/springMVC-servlet.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <beans:beans xmlns:beans="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
        xmlns:context="http://www.springframework.org/schema/context"
        xmlns:mvc="http://www.springframework.org/schema/mvc" 
        xmlns:p="http://www.springframework.org/schema/p"
        xsi:schemaLocation="
            http://www.springframework.org/schema/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.org/schema/context 
            http://www.springframework.org/schema/context/spring-context-3.0.xsd" >
            
        <context:component-scan base-package="www.xi.com" />
        
        <mvc:annotation-driven />
        
        <beans:bean id="viewResolver"
            class="org.springframework.web.servlet.view.InternalResourceViewResolver">
            <beans:property name="prefix" value="/WEB-INF/jsp/" />
            <beans:property name="suffix" value=".jsp" />
        </beans:bean>
     </beans:beans>

    touch jsp/hello.jsp
      文件名称很重要!

    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    </head>
    <body>
    "hello world"
    </body>
    </html>

    touch www.xi.com.mvcController.java

    package www.xi.com;
    
    import org.apache.commons.logging.Log;
    import org.apache.commons.logging.LogFactory;
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.RequestMapping;
    
    @Controller
    public class mvcController {
    
        private static final Log logger = LogFactory.getLog(mvcController.class);
    
        @RequestMapping("/hello")
        public String hello() {
            logger.info("hello called");
    
            return "hello";
        }
    
    }


    执行访问:
    http://localhost:8080/SpringMVC/hello

    显示:

    “hello world”
    3.问题
    1.Spring MVC常用注解有哪些?

    2.Spring MVC的基本流程是什么?

    3.接口解释
    DispatcherServlet
    WebApplicationContext
    HandlerMapping
    HandlerAdapter
    Controllers
    ViewResolver
    LocaleResolver & LocaleContextResolver
    HandlerExceptionResolver
    ThemeResolver
    MultipartResolver
    FlashMapManager

    4.Servlet,JSP基础概念

    5.xml中如何知道有哪些标签,以及标签的意义等?

  • 相关阅读:
    C/C++产生随机数
    BNUOJ34973Liserious战队
    oracle ebs 12.20 安装成功其过程失败日记及总结(1)
    HDU 2544 最短路 SPFA 邻接表 模板
    GridView编辑删除操作
    Hibernate_10_继承的例子_单表
    String不变性
    Mac在结构quick cocos2d-x编译环境
    Hash散列算法 Time33算法
    南京地图南京全套的卫星地图下载 百度高清卫星地图包括道路、标签信息叠加
  • 原文地址:https://www.cnblogs.com/xixiaohui/p/7527427.html
Copyright © 2011-2022 走看看