一、新建项目

SpringMVC_HelloWorld_01

二、配置文件

1、配置web.xml

<?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">
<!-- The front controller of this Spring Web application, responsible for
handling all application requests -->
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet> <!-- Map all requests to the DispatcherServlet for handling -->
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>

2、配置springmvc-servlet.xml

<?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:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd"> <!-- 配置扫描自定义的包 -->
<context:component-scan base-package="com.zhy.controllers"></context:component-scan> <!-- 配置视图解析器 -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<!-- 配置前缀 -->
<property name="prefix" value="/WEB-INF/views/"></property>
<!-- 配置后缀 -->
<property name="suffix" value=".jsp"></property>
</bean>
</beans>

三、编写Controller

package com.zhy.controllers;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping; @Controller
public class HelloWorldController { /*
* 通过视图解析器(ViewResolver)得到实际的物理视图
* 视图解析器的解析规则:prefix + returnvalue + suffix
* 结合本实例,视图解析器的解析出来的物理视图为:/WEB-INF/views/helloworld.jsp
* */
@RequestMapping("/mvc")
public String hello(){ System.out.println("call controller");
return "helloworld";
}
}

四、新建jsp页面

SpringMVC_HelloWorld_01

四、运行

SpringMVC_HelloWorld_01

SpringMVC_HelloWorld_02的更多相关文章

随机推荐

  1. hql和sql练习题

    SQL与HQL练习题 中的所有员工. select * from emp where deptno = 30 from  Emp  e  where e.deptno = 30 2. 列出所有办事员( ...

  2. android 之 Hnadler 、Message 、Looper

    Handler定义: 主要接受子线程发送来的数据,并用此数据配合主线程更新UI. 为什么要用Handler? 我们手机当中的很多功能或操作是不能都放在Activity当中的,比如下载文件.处理大量数据 ...

  3. linux动态库与静态库混合连接

      1, 在应用程序需要连接外部库的情况下,linux默认对库的连接是使用动态库,在找不到动态库的情况下再选择静态库.使用方式为: gcc test.cpp -L. -ltestlib 如果当前目录有 ...

  4. (转)Spring文件上传,包括一次选中多个文件

    背景: http://www.cnblogs.com/lixuwu/p/8495275.html已经实现了单文件的上传和下载,多文件的上传是另一种情景,这里记录下来 实现过程 先说前台. 运行以后就是 ...

  5. linux下查找某文件关键字(grep 函数)

    -e表示罗列出与关键字有关的行,“ABC”表示查找的关键字,/XXX/4.assoc.linear表示该路径下的文件 .assoc.linear

  6. CSS3:文字属性

    文字属性注意的细节: <!DOCTYPE html> <html lang="en"> <head> <meta charset=&quo ...

  7. Elasticsearch日志分析系统

    Elasticsearch日志分析系统 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.什么是Elasticsearch 一个采用Restful API标准的高扩展性的和高可用性 ...

  8. 1、Python-HelloWorld

    安装 环境下载 https://www.python.org/downloads/ IDE(PyCharm)下载 https://www.jetbrains.com/pycharm/download/ ...

  9. Jupyter 魔术命令(magic commands)

    自动重新加载更改的模块 命令参数如下所示: %autoreload: 自动重载%aimport排除的模块之外的所有模块. %autoreload 0: 禁用自动重载 %autoreload 1: 自动 ...

  10. ECSHOP /mobile/admin/edit_languages.php

    漏洞名称:ecshop代码注入漏洞 补丁编号:10017531 补丁文件:/mobile/admin/edit_languages.php 补丁来源:云盾自研 更新时间:2017-01-05 08:4 ...