SpringMVC_HelloWorld_02
一、新建项目
二、配置文件
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_02的更多相关文章
随机推荐
- python assert用法
使用assert断言是学习python一个非常好的习惯,python assert 断言句语格式及用法很简单.在没完善一个程序之前,我们不知道程序在哪里会出错,与其让它在运行最崩溃,不如在出现错误条件 ...
- Android学习系列(17)--App列表之圆角ListView(续)
http://www.cnblogs.com/qianxudetianxia/archive/2011/09/19/2068760.html 本来这篇文章想并到上篇Android学习系列(16)- ...
- Qt程序ibus输入法不跟随
在Qt程序中ibus框架的输入法无法跟随光标所在的位置,会出现如图所示的效果. 解决方法 安装qt4-qtconfig和ibus-qt4. 运行qtconfig,在界面-XIM输入风格中,选择光标跟随 ...
- 【UR #17】滑稽树前做游戏
假装看懂的样子 假装会做的样子 UOJ Round #17 题解 加上一个(t-w)^c,c是和i相连的点的度数 是一个多项式的话可以归纳证明 一些具体实现: 多项式存储,保留t,y, f=ai*t^ ...
- c++11并发之std::thread
知识链接: https://www.cnblogs.com/lidabo/p/7852033.html 构造函数如下: ) thread() noexcept; initialization() te ...
- The 2016 ACM-ICPC Asia Beijing Regional Contest E - What a Ridiculous Election
https://vjudge.net/contest/259447#problem/E bfs,k个限制条件以数组的额外k维呈现. #include <bits/stdc++.h> usi ...
- MATLAB:图像减法运算(imsubtract函数)
图像减法运行涉及到imsubtract函数 实现代码如下: clear all; %关闭当前所有图形窗口,清空工作空间变量,清除工作空间所有变量 clc close all; A=imread('ca ...
- 使用LTP套件对Linux系统进行压力测试
使用LTP套件对Linux系统进行压力测试 https://www.ubuntukylin.com/ukylin/forum.php?mod=viewthread&tid=6764 https ...
- C# BindingSource
1.引言 BindingSource组件是数据源和控件间的一座桥,同时提供了大量的API和Event供我们使用.使用这些API我们可以将Code与各种具体类型数据源进行解耦:使用这些Event我们可以 ...
- 爬虫处理网站的bug---小于号未转化为实体符
1.发现BUG 爬取 chinadrugtrials 详情页的公示的试验信息时候, 发现程序在某些地方跑断掉了,如下: 经排查发现,原来这是网页的bug-----极少数详情页面的某些文字中的小于号,未 ...