1. Configuration of maven, pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.cisco</groupId><artifactId>eStore</artifactId><packaging>war</packaging><version>1.0-SNAPSHOT</version><properties><spring.version>5.0.5.RELEASE</spring.version><servlet.version>3.0.1</servlet.version></properties><dependencies><dependency><groupId>javax.servlet</groupId><artifactId>javax.servlet-api</artifactId><version>${servlet.version}</version><scope>compile</scope></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-core</artifactId><version>${spring.version}</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-beans</artifactId><version>${spring.version}</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>${spring.version}</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-web</artifactId><version>${spring.version}</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-webmvc</artifactId><version>${spring.version}</version></dependency></dependencies></project>

The core/context/beans is the basic core components of Spring framework. And the servlet is necessary for web project.

2. create the simplest project hierarchy

3. web.xml config

<?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" version="3.0"><display-name>Archetype Created Web Application</display-name><servlet><servlet-name>spring-mvc</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><load-on-startup>1</load-on-startup></servlet><servlet-mapping><servlet-name>spring-mvc</servlet-name><url-pattern>/</url-pattern></servlet-mapping><welcome-file-list><welcome-file>/demo/index</welcome-file></welcome-file-list>
</web-app>

4. spring-mvc-servlet.xml

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

5. Controller

package com.cisco.eStore.controller;import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;@Controller
@RequestMapping("/demo")
public class HelloWorldController {@RequestMapping("index")public String index(Model model){model.addAttribute("msg","Hello World!");return "demo";}}

6. view/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>首页</title>
</head>
<body>
<h1>This is SpringMVC Demo</h1>
${msg}
</body>
</html>

Conclusion:

The dispatchServlet is the main entry for spring mvc framework. Every request will first enter the dispatcherServlet, then using the spring rule to dispatcher to your controller or handler or interceptor .

[eStore] Build simplest spring MVC project with maven相关推荐

  1. 第一个使用Spring Tool Suite(STS)和Maven建立的Spring mvc 项目

    一.目标 在这篇文章中.我将要向您展示怎样使用Spring Frameworks 和 Maven build创建您的第一个J2ee 应用程序. 二.信息 Maven是一个java项目的构建工具(或者自 ...

  2. Spring MVC Maven 环境搭建与部署

    本文简单演示了本地开发环境的搭建.项目出包.部署运行.HelloWorld,以及部分注意事项. 起初的玩法:先安装Eclipse,然后分别下载并安装Maven.spring的插件,再进行工程模式转换, ...

  3. Spring MVC 4快速入门Maven原型得到了改进–更多Java 8功能

    对于所有有兴趣在没有Spring Boot的情况下快速引导Spring 4应用程序的开发人员,请检查刚刚更新的我的Spring MVC 4 Quickstart Maven原型. 原型已经将Java ...

  4. Spring MVC 4快速入门Maven原型已改进

    Spring Boot使Spring入门非常容易. 但是仍然有人对不使用Spring Boot并以更经典的方式引导应用程序感兴趣. 几年前,我创建了一个原型(早于Spring Boot),简化了引导S ...

  5. spring mvc示例_Spring MVC示例

    spring mvc示例 Welcome to Spring MVC Example. Sometime back in Spring MVC Tutorial, I explained how to ...

  6. spring mvc国际化_Spring MVC国际化(i18n)和本地化(L10n)示例

    spring mvc国际化 Welcome to the Spring Internationalization (i18n) tutorial. Any web application with u ...

  7. Spring MVC 如何上传多个文件到指定位置

    Spring MVC 如何上传多个文件到指定位置 太阳火神的美丽人生 (http://blog.csdn.net/opengl_es) 本文遵循"署名-非商业用途-保持一致"创作公 ...

  8. Spring MVC工程搭建

    SpringMVC请求映射注解请求映射注解 请求映射注解 说明 @RequestMapping 通用的请求处理 @GetMapping 处理 HTTP GET 请求 @PostMapping 处理 H ...

  9. Spring MVC-使用Spring Tool Suite IDE搭建Spring MVC开发环境

    Spring MVC 概述 新建Spring MVC Project 分析IDE建立的工程 Maven dependencies configuration Spring MVC configurat ...

最新文章

  1. 关于GCN,我有三种写法
  2. SAP PM创建多语言文本
  3. 云安全云计算 迷团大揭幕
  4. 微软Windows Azure Platform技术解析
  5. java源文件怎么发送给别人_自己的java程序怎么给别人用
  6. Cookie或将被替换!Chrome工程师提议新型HTTP状态管理协议
  7. 第三部分:Android 应用程序接口指南---第三节:应用程序资源---第四章 本地化...
  8. Ch2 空间配置器(allocator) ---笔记
  9. Linux基本操作——文件相关
  10. 组策略同步的频率和设置修改
  11. 使用frp实现将内网映射到公网 无需花生壳
  12. mapreduce的二次排序 SecondarySort
  13. OS X 使用技巧——在Finder窗口标题栏上显示路径
  14. STL - queue(队列)
  15. 趋势 | 2020年云计算的10大市场方向
  16. 清华计算机系研究生刘艺华,2017年清华大学计算机系硕士录取名单
  17. 【2017年第4期】面向特定领域大数据平台架构及标准化研究
  18. html正方形项目符号,html自定义项目符号
  19. 扫描探针显微术入门(4)
  20. 支配树学习思路/模板

热门文章

  1. Spring中用了哪些设计模式
  2. BUUCTF Web [BSidesCF 2019]Kookie1 [BSidesCF 2019]Futurella1
  3. python 多媒体框架pyglet开发
  4. 第一批吃螃蟹的人:浙大全日制英文MBA复试经验分享
  5. GO语言学习笔记之channel
  6. 使用最大-最小树搜索算法和alpha-beta剪枝算法设计有效围棋走法
  7. get和post方法使用建议
  8. ASR 隐马尔可夫模型(HMM)
  9. 关于无人机的智能吊舱项目的开发小结
  10. 前端网站推荐--(转自知乎)