1、先看下目录结构

2、引用所需的jar文件

3、web.xml 配置如下

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<!-- 监听所有请求 -->
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>

4、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/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
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">
<!-- 扫描所有的 controller -->
<context:component-scan base-package="controller" />
<!-- 启动注解驱动 SpringMVC 功能 -->
<mvc:annotation-driven />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/views/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>

5、根目录下新寻views文件夹在里面新建home子文件夹然后再新建 index.jsp(普通页面)
index.jsp

<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>"> <title>My JSP 'index.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
--> </head> <body>
This is my JSP page. <br>
</body>
</html>

HomeController内容如下:

package controller;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Iterator;
import java.util.List; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.servlet.ModelAndView; @Controller
public class HomeController { /*
* 首页
*/
@RequestMapping(value="/index")
public String index(Model model){
return "/index";
}
}

启动开发工具或tomcat之后访问:http://localhost:8080/index 就能浏览到index.jsp里面的内容。

springmvc 入门级教程的更多相关文章

  1. Android Studio 入门级教程(三):gradle项目构建

    声明 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/4456420.html [系列] Andr ...

  2. Android Studio 入门级教程(二):新建一个属于自己的工程并安装Genymotion模拟器

    声明 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/4392611.html [系列] Andr ...

  3. Android Studio 入门级教程(一)

    声明 AS已经是Android开发的主流工具了,但是学校教学用的还是eclipse,很多同学不知道如何入门.网上看到一位大神整理得很好的教程,转载过来,希望可以帮到有需要的人. 生命壹号:http:/ ...

  4. Android Studio 入门级教程

    引用原文:http://www.cnblogs.com/abao0/p/6934023.html 写博客是为了记住自己容易忘记的东西,另外也是对自己工作的总结,文章可以转载,无需版权.希望尽自己的努力 ...

  5. springmvc简单教程

    IDEA建立Spring MVC Hello World 详细入门教程(转自)   引子,其实从.NET转Java已经有几个月时间了,项目也做了不少,但是很多配置都是根据公司模板或者网上教程比忽略画瓢 ...

  6. webpack入门级教程

    Webpack是什么 首先可以看下官方文档,文档是最好的老师. 这里也有国外的一个朋友写的入门介绍. Webpack是由Tobias Koppers开发的一个开源前端模块构建工具.它的基本功能是将以模 ...

  7. SpringMVC 系列教程1-文件上传-配置

    SpringMVC默认没有配置上传解析器 使用SpringMVC来处理上传必须添加对MultipartResolver上传解析器的声明配置. 配置之后,客户端每次进行请求的时候,SpringMVC都会 ...

  8. [Splay伸展树]splay树入门级教程

    首先声明,本教程的对象是完全没有接触过splay的OIer,大牛请右上角.. 首先引入一下splay的概念,他的中文名是伸展树,意思差不多就是可以随意翻转的二叉树 PS:百度百科中伸展树读作:BoGa ...

  9. 全网首创ISE入门级教程

    转眼间我已经大三了,现在成为了实验室的负责人,对于下一届学生的纳新重任就交到了我的手上,想采取不同的方法暑假尽可能对他们进行一些培训,所以制作了此教程,说实话,在网上还没有找到关于ISE的入门级使用教 ...

随机推荐

  1. 540B :School Marks

    题目链接 题意: 输入: 第一个: n k p x y 第二行:k个数 n: 数的数量 k:n个数中已经知道的k个数 p:n个数取值的上界,下界是1 x:n个数的和的上界x y:n个数的中位数至少是 ...

  2. 关于 RTMP RTMPT RTMPS RTMPE RTMPTE RTMFP AMF 简介

    http://www.360doc.com/content/13/0709/16/21412_298738723.shtml 1. AMFAMF(是Action Message Format的缩写)是 ...

  3. eclipse导入maven项目后依赖jar包更新问题->update project按钮

    eclipse导入maven项目后依赖jar包更新问题 1.eclipse有专门的导入maven项目按钮,file-import-maven project,eclipse会自动查找指定路径下的pom ...

  4. Linux服务器 scp 不需要密码配置与密钥转换(id_rsa->ppk)

    案例:▲服务器A对服务器B.C进行ssh连接,免输入密码    或▲服务器A向服务器B.C复制文件(源文件在服务器A上),免输入密码 主机A:192.168.0.221主机B:192.168.0.22 ...

  5. 使用 JAX-RS 简化 REST 应用开发

    本文将详细介绍 Java EE 6 中所引入的对 JSR-311 (JAX-RS : Java API for RESTful Web Services) 的支持,并通过一个完整的示例应用程序展示 J ...

  6. 一行代码设置TLabel.Caption的前世今生

    第零步,测试代码: procedure TForm1.Button1Click(Sender: TObject); begin Label1.Caption := 'Hello World'; end ...

  7. CentOS编译安装Python3

    前话 最近想学一下一门新的高级语言,无意中看到用python仿AIphaGo的github项目,就决定是他了. AIphaGo的Git传送门: https://github.com/Rochester ...

  8. 298. Binary Tree Longest Consecutive Sequence

    题目: Given a binary tree, find the length of the longest consecutive sequence path. The path refers t ...

  9. 293. Flip Game

    题目: You are playing the following Flip Game with your friend: Given a string that contains only thes ...

  10. 在CentOS 7中安装与配置Tomcat-8方法

    安装前提 在CentOS 7中安装与配置JDK8 安装tomcat  apache-tomcat-8.0.14.tar.gz文件上传到/usr/local中执行以下操作: [root@localhos ...