一、新建项目

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. 【模板】kmp

    引理:当计算第 \(i\) 位的失配指针时,若 \(j_0\) 是一个候选条件,那么小于 \(j_0\) 的最大候选条件是 \(fail[j_0]\). 证明:反证法.假设存在 \(j_1\),使得\ ...

  2. EOJ2018.10 月赛(A 数学+思维题)

    传送门:Problem A https://www.cnblogs.com/violet-acmer/p/9739115.html 题意: 能否通过横着排或竖着排将 1x p 的小姐姐填满 n x m ...

  3. (Arrays.sort() 或 map) Ignatius and the Princess IV hdu1029

    Ignatius and the Princess IV 链接:http://acm.hdu.edu.cn/showproblem.php?pid=1029 借鉴链接:https://blog.csd ...

  4. HTTP Status 405 - HTTP method POST is not supported by this URL

    出现这个问题, 1.在servlet中没有调用post()方法引起的 2.在serlvet中跳转没有用外跳(response.sendRedirect()) 我的是因为第一种,是没有写dopost() ...

  5. Prometheus+grafana搭建

    一.简介 1.1 Prometheus Prometheus是一套开源的监控系统,它将所有信息都存储为时间序列数据:因此实现一种Profiling监控方式,实时分析系统运行的状态.执行时间.调用次数等 ...

  6. java程序中加入@SuppressWarnings("serial")是什么意思?

    比如有个类实现了java.io.Serialize接口:package com.onede4.test; public class TestSerial implements java.io.Seri ...

  7. 继承之es5对比es6

    es5: 熟悉es5的童鞋们就知道es5的继承多么恶心~~ es5最经典的继承写法就是如下这样 1.写一个function,用this来扩展其值类属性 2.prototype添加其方法类属性 3.若整 ...

  8. IOS绘图的核心步骤

    在view上绘制一个图形的方式有很多种,表现形式可能不一样,但其实质步骤都是一样的: 1)获取上下文 2)绘制路径 3)添加路径到上下文 4)修改图形状态参数 5)渲染上下文 下面我们以画一个圆形来演 ...

  9. 用java发邮件之一 (直接源于真实项目) 【原】

    真实项目应用的java发送邮件,应该还待进一步完善. 依赖 mail-1.4.jar jar包下载地址: http://mvnrepository.com/artifact/javax.mail/ma ...

  10. 一步一步配置 Dell OME 监控 Dell 服务器硬件报警

    本文包括以下四个部分: 下载 Dell OME 安装 Dell OME 配置 Dell OME 配置 iDRAC 下载 Dell OME 以Dell PowerEdge R730xd 为例 1.登录 ...