1、新建一个Java Web项目

2、导入jar包

3、在WEB-INF下面建一个hello.jsp页面。

 1 <%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
2
3 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
4 <html>
5 <head>
6 <title>My JSP 'hello.jsp' starting page</title>
7 </head>
8
9 <body>
10 hello springmvc
11 </body>
12 </html>

4、配置web.xml文件

 1 <?xml version="1.0" encoding="UTF-8"?>
2 <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">
3
4 <servlet>
5 <servlet-name>dispatcherServlet</servlet-name>
6 <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
7 <init-param>
8 <param-name>contextConfigLocation</param-name>
9 <param-value>classpath:spring-mvc.xml</param-value>
10 </init-param>
11 <load-on-startup>1</load-on-startup>
12 </servlet>
13
14 <servlet-mapping>
15 <servlet-name>dispatcherServlet</servlet-name>
16 <url-pattern>/</url-pattern>
17 </servlet-mapping>
18
19 <welcome-file-list>
20 <welcome-file>index.jsp</welcome-file>
21 </welcome-file-list>
22 </web-app>

5、配置spring-mvc.xml文件

 1 <?xml version="1.0" encoding="UTF-8"?>
2 <beans xmlns="http://www.springframework.org/schema/beans"
3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4 xmlns:context="http://www.springframework.org/schema/context"
5 xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
6 http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd">
7
8 <context:component-scan base-package="com.proc"></context:component-scan>
9
10 <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
11 <property name="prefix" value="/WEB-INF/"/>
12 <property name="suffix" value=".jsp"></property>
13 </bean>
14 </beans>

  InternalResourceViewResolver:视图解析器。根据Url地址遭到找到文件资源

    prefix:前缀

    suffix:后缀

6、配置控制器

 1 package com.proc;
2
3 import org.springframework.stereotype.Controller;
4 import org.springframework.web.bind.annotation.RequestMapping;
5
6 @Controller
7 public class Hello {
8
9 @RequestMapping("/hello")
10 public String hello(){
11 System.out.println("hello springmvc");
12 return "hello";
13 }
14 }

  @RequetMapping注解作用是url映射

测试访问

Spring MVC入门示例(1)的更多相关文章

  1. 【转】spring MVC入门示例(hello world demo)

    部分内容来自网络:<第二章 Spring MVC入门 —— 跟开涛学SpringMVC > 1. Spring MVC介绍 Spring Web MVC是一种基于Java的实现了Web M ...

  2. 1.【转】spring MVC入门示例(hello world demo)

    1. Spring MVC介绍 Spring Web MVC是一种基于Java的实现了Web MVC设计模式的请求驱动类型的轻量级Web框架,即使用了MVC架构模式的思想,将web层进行职责解耦,基于 ...

  3. Spring MVC 入门示例讲解

    在本例中,我们将使用Spring MVC框架构建一个入门级web应用程序.Spring MVC 是Spring框架最重要的的模块之一.它以强大的Spring IoC容器为基础,并充分利用容器的特性来简 ...

  4. Spring MVC 入门示例讲解 - howtodoinjava

    在本例中,我们将使用Spring MVC框架构建一个入门级web应用程序.Spring MVC 是Spring框架最重要的的模块之一.它以强大的Spring IoC容器为基础,并充分利用容器的特性来简 ...

  5. spring mvc 入门示例

    classpath <?xml version="1.0" encoding="UTF-8"?> <classpath> <cla ...

  6. Spring MVC入门示例

    1.新建一个Java Web项目 2.导入jar包 3.在WEB-INF下面建一个hello.jsp页面. <%@ page language="java" import=& ...

  7. Spring MVC 入门教程示例 (一)

    今天和大家分享下  Spring MVC  入门教程 首先还是从 HelloWorld  web 工程开始 -------------------------- 1.首先创建一个Maven Web工程 ...

  8. Spring框架学习(7)spring mvc入门

    内容源自:spring mvc入门 一.spring mvc和spring的关系 spring mvc是spring框架提供的七层体系架构中的一个层,是spring框架的一部分,是spring用于处理 ...

  9. Java基础-SSM之Spring MVC入门篇

    Java基础-SSM之Spring MVC入门篇 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.Spring MVC简介 1>.什么是Spring MVC 答:Sprin ...

随机推荐

  1. Java-Class-C:cn.hutool.core.date.DateUtil

    ylbtech-Java-Class-C:cn.hutool.core.date.DateUtil 1.返回顶部   2.返回顶部 1.1. import cn.hutool.core.date.Da ...

  2. POJ 3468 A Simple Problem with Integers (分块)

    Description You have \(N\) integers, \(A_1, A_2, ... , A_N\). You need to deal with two kinds of ope ...

  3. cesium相关学习网址

    cesium相关学习网址: cesium资料大全网址:https://www.cnblogs.com/cesium1/p/10062942.html       http://192.168.101. ...

  4. Java8 时间调节器

    TemporalAdjuster 是做日期数学计算.例如,要获得“本月第二个星期六”或“下周二”. 让我们来看看他们的操作. 选择使用任何编辑器创建以下java程序在 C:/> JAVA Jav ...

  5. 20140814 explicit

    1.explicit explicit   只对构造函数起作用,用来抑制隐式转换. 如:     class   A   {        A(int   a);   };  int   Functi ...

  6. NIO 源码分析(04) 从 SelectorProvider 看 JDK SPI 机制

    目录 一.SelectorProvider SPI 二.SelectorProvider 加载过程 2.1 SelectorProvider 加载 2.2 Windows 下 DefaultSelec ...

  7. Python中两大神器&exec() &eval()

    一.神器1 -- 内置函数eval eval是python中的内置函数,它的作用是将字符串变为所对应的表达式,也相当于一个功能代码加双引号变为字符串,而eval又将字符串转为相应的功能,它在使用过程中 ...

  8. 长度为x的本质不同的串的出现次数 SPOJ - NSUBSTR 后缀自动机简单应用

    题意: 长度为x的本质不同的串的出现次数 题解: 先处理出每一个节点所对应的子串出现的次数 然后取max就好了 #include <set> #include <map> #i ...

  9. SSD 坏了

    系统盘是SSD,系统盘坏了. 桌面所有数据都拿不回来了. 真的无奈啊,来吧,统计一下,有多少东西要重装. VS2008.VS2010.VS2013.VS2015. GITHUB.SVN.VMWare. ...

  10. debug breakpoint with maven in eclipse