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映射

测试访问

本文转自:http://www.cnblogs.com/caoyc/p/5635101.html

最新文章

  1. 彻底解决“从客户端中检测到有潜在危险的Request.Form值”
  2. ecshop 后台【左侧新增菜单】
  3. golang的第一个deadlock
  4. php yii多表查询
  5. 浏览器页面区域大小的js获取方法
  6. Otto开发初探——微服务依赖管理新利器
  7. 为什么选择我--ReactJS
  8. framework层和native层实现联网控制(iptable方式)
  9. eclipse打不开data目录解决的方法
  10. hdu_3564_Another LIS(线段树+LIS)
  11. XSS注入,js脚本注入后台
  12. 海量数据挖掘MMDS week2: Association Rules关联规则与频繁项集挖掘
  13. springboot~ObjectMapper~dto到entity的自动赋值
  14. error #10234-D: unresolved symbols remain error #10010: errors encountered during linking;
  15. Dragger2好网文整合
  16. DotNetCore依赖注入实现批量注入
  17. (转)netty、mina性能对比分析
  18. Packet for query is too large (5,145 &gt; 1,024). You can change this value on the server by setting the &#39;max_allowed_packet&#39; variable.
  19. CodeForces 297C Splitting the Uniqueness (脑补构造题)
  20. Oracle OCI操作UDT相关学习(二)

热门文章

  1. oracle数据库面试相关
  2. Delphi DBGridEh导出Excel
  3. golang基础学习-MongoDB使用
  4. 6.3.2巴特沃斯(butterworth)低通滤波器
  5. CSS3 —— 文本 背景 列表 渐变
  6. Python学习之数据库初识
  7. 【miscellaneous】GPRS本质论
  8. Linux用ICMP协议实现简单Ping网络监测功能
  9. tp5后台同步更新配置文件
  10. PHP:API 接口规范完整版本