IDE:Eclipse Jee

JDK:8

Tomcat:8

1.创建项目

File->New->Maven Project->

->Next->

->Next->

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbGFuZV9s/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">

->Finished

2.加入包

右击项目->Build Path->Configure Build Path->Add Library->

->Next->选择Tomcat->FInished->

右键项目->Run as->Maven install

3.编辑pox.xml

双击pox.xml->Dependencies->Add->

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbGFuZV9s/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">

->继续Add->

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbGFuZV9s/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">

4.编写代码

  1. package com.kang.controllers;
  2.  
  3. import org.springframework.stereotype.Controller;
  4. import org.springframework.web.bind.annotation.RequestMapping;
  5. import org.springframework.web.bind.annotation.RequestParam;
  6. import org.springframework.web.servlet.ModelAndView;
  7.  
  8. @Controller
  9. public class IndexController {
  10. @RequestMapping(value="/hello")
  11. public ModelAndView toindex(@RequestParam(value="name")String name){
  12. ModelAndView mv = new ModelAndView();
  13. mv.setViewName("index");
  14. mv.addObject("name",name);
  15. return mv;
  16. }
  17.  
  18. }

  1. <?
  2.  
  3. xml version="1.0" encoding="UTF-8"?>
  4. <beans xmlns="http://www.springframework.org/schema/beans"
  5. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  6. xmlns:context="http://www.springframework.org/schema/context"
  7. xmlns:mvc="http://www.springframework.org/schema/mvc"
  8. xsi:schemaLocation="http://www.springframework.org/schema/beans
  9. http://www.springframework.org/schema/beans/spring-beans.xsd
  10. http://www.springframework.org/schema/context
  11. http://www.springframework.org/schema/context/spring-context-3.2.xsd
  12. http://www.springframework.org/schema/mvc
  13. http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">
  14.  
  15. <!-- 注解扫描包 -->
  16. <context:component-scan base-package="com.kang.controllers" />
  17.  
  18. <!-- 开启注解 -->
  19. <mvc:annotation-driven ></mvc:annotation-driven>
  20.  
  21. <mvc:default-servlet-handler/>
  22.  
  23. <!-- 定义视图解析器 -->
  24. <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
  25. <property name="prefix" value="/WEB-INF/views/"></property>
  26. <property name="suffix" value=".jsp"></property>
  27. </bean>
  28.  
  29. </beans>

  1. <%@ page language="java" contentType="text/html; charset=UTF-8"
  2. pageEncoding="UTF-8"%>
  3. <%@ page isELIgnored="false"%>
  4. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  5. <html>
  6. <head>
  7. <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
  8. <title>Insert title here</title>
  9. </head>
  10. <body>
  11. Hello,${name}!
  12. </body>
  13. </html>

  1. <?
  2.  
  3. xml version="1.0" encoding="UTF-8"?>
  4. <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  5. <display-name>Test</display-name>
  6. <welcome-file-list>
  7. <welcome-file>index.jsp</welcome-file>
  8. </welcome-file-list>
  9.  
  10. <!-- 配置Spring监听 -->
  11. <listener>
  12. <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  13. </listener>
  14.  
  15. <!-- 载入全部的配置文件 -->
  16. <context-param>
  17. <param-name>contextConfigLocation</param-name>
  18. <param-value>classpath:spring-*.xml</param-value>
  19. </context-param>
  20.  
  21. <listener>
  22. <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
  23. </listener>
  24.  
  25. <!-- 配置SpringMVC -->
  26. <servlet>
  27. <servlet-name>springMVC</servlet-name>
  28. <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  29. <init-param>
  30. <param-name>contextConfigLocation</param-name>
  31. <param-value>classpath:spring-mvc.xml</param-value>
  32. </init-param>
  33. <load-on-startup>1</load-on-startup>
  34. </servlet>
  35. <servlet-mapping>
  36. <servlet-name>springMVC</servlet-name>
  37. <url-pattern>/</url-pattern>
  38. </servlet-mapping>
  39.  
  40. <!-- 配置字符集 -->
  41. <filter>
  42. <filter-name>encodingFilter</filter-name>
  43. <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
  44. <init-param>
  45. <param-name>encoding</param-name>
  46. <param-value>UTF-8</param-value>
  47. </init-param>
  48. <init-param>
  49. <param-name>forceEncoding</param-name>
  50. <param-value>true</param-value>
  51. </init-param>
  52. </filter>
  53.  
  54. <filter-mapping>
  55. <filter-name>encodingFilter</filter-name>
  56. <url-pattern>/*</url-pattern>
  57. </filter-mapping>
  58.  
  59. </web-app>

5.执行项目

右键项目->Run as->Run on Server->选择Tomcat->Finished

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbGFuZV9s/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">

用Maven创建SpringMVC项目的更多相关文章

  1. 工具idea 基于maven 创建springMVC项目

    SpringMVC Spring MVC是Spring提供的一个强大而灵活的web框架.借助于注解,Spring MVC提供了几乎是POJO的开发模式,使得控制器的开发和测试更加简单.这些控制器一般不 ...

  2. 在eclipse中使用maven创建springMVC项目

    一.在eclipse中创建maven-archetype-webapp项目: 1.新建项目选择maven项目 2.默认,下一步 3.选择maven-archetype-webapp,其他保持默认即可 ...

  3. IDEA用maven创建springMVC项目和配置

    工具准备:IDEA2016.3 Java jdk 1.8 1.DEA创建项目 新建一个maven project,并且选择webapp原型.  然后点击next  这里的GroupId和Artifac ...

  4. IDEA用maven创建springMVC项目和配置(XML配置和Java配置)

    1.DEA创建项目 新建一个maven project,并且选择webapp原型. 然后点击next 这里的GroupId和ArtifactID随意填写,但是ArtifactID最好和你的项目一名一样 ...

  5. SpringMVC教程--eclipse中使用maven创建springMVC项目

    一.在eclipse中创建maven-archetype-webapp项目: 1.新建项目选择maven项目 2.默认,下一步 3.选择maven-archetype-webapp,其他保持默认即可 ...

  6. SpringMVC教程--Idea中使用Maven创建SpringMVC项目

    1.新建项目 参照idea教程中的创建maven项目https://www.cnblogs.com/daxiang2008/p/9061653.html 2.POM中加入依赖包 (1)指定版本 (2) ...

  7. maven创建springMVC项目(一)

    1.Eclipse配置 添加maven集成安装包:路径是maven下载安装的解压位置,如果不知道如何下载安装请点击这里看我的另一篇安装文章,这里不多说 这里需要注意的是: a.settings.xml ...

  8. Intellij IDEA创建git,maven的SpringMVC项目

    Intellij IDEA创建git,maven的SpringMVC项目 原文链接:http://www.cnblogs.com/blog5277/p/8906120.html 原文作者:博客园--曲 ...

  9. 简述泛型、用Maven创建Web项目以及在Web项目上整合SpringMVC

    表设计 Timestamp列是否取消"根据当前时间戳自动更新" 是否null及默认值选择合理不合理 外键命名规范及更新和删除时的动作是否合理   泛型 类型参数 --允许在外部指定 ...

随机推荐

  1. springboot actuator shutdown正确的关闭操作

    今天整合ehcache时发现一个很重要的问题,就是程序关闭(硬关闭)之后,持久化到磁盘的缓存数据没能正确写入加载,问题还是硬关闭的问题,所以就使用actuator 进行监听 <dependenc ...

  2. vue组件父子之间相互通信案例

  3. c# 值类型 之枚举

    1声明枚举(enum)类型的变量 enum 变量名 { //标识符列表中,元素与元素之间用 , 逗号分隔: 标识符列表 } 枚举列表中的每个符号代表一个整数值,一个比他前面符号大的整数值,默认情况下, ...

  4. 51Nod 独木舟(贪心)

    n个人,已知每个人体重.独木舟承重固定,每只独木舟最多坐两个人,可以坐一个人或者两个人.显然要求总重量不超过独木舟承重,假设每个人体重也不超过独木舟承重,问最少需要几只独木舟? Input 第一行包含 ...

  5. 不再安全的 OSSpinLock

    自旋锁的本质是持续占有cpu,直到获取到资源.与其他锁的忙等待的实现机制不同. 昨天有位开发者在 Github 上给我提了一个 issue,里面指出 OSSpinLock 在新版 iOS 中已经不能再 ...

  6. NodeJS学习笔记 进阶 (8)express+morgan实现日志记录(ok)

    个人总结:这篇文章讲解了Express框架中日志记录插件morgan的示例.读完这篇文章需要10分钟 摘选自网络 章节概览 morgan是express默认的日志中间件,也可以脱离express,作为 ...

  7. NOIP 2017 小凯的疑惑(同余类)

    题意 给出两个互质的数a,b问最大的不能被xa+yb(x,y>=0)表示的数.(a,b<=109) 题解 NOIPday1T1一道数论题,不知埋葬了多少人的梦想. 用同余类去解释. 我们依 ...

  8. cmder-替代cmd

    之所以选择cmder,说来话长,在学习python的过程中,由于经常通过pip命令安装包,并且在学习一些包的使用例如virtualenv,教程贴都是在终端下的命令,这使我对cmd的使用频率慢慢变多了起 ...

  9. 洛谷P1006 传纸条 (棋盘dp)

    好气,在洛谷上交就过了,在caioj上交就只有40分 之前在51nod做过这道题了. https://blog.csdn.net/qq_34416123/article/details/8180902 ...

  10. Objective-C中的同步线程的锁

    概述 在多线程编程中往往会遇到多个线程同时访问共享的资源,这种情况我们需要通过同步线程来避免.也就是给线程加锁. 因为Objective-C是C语言的超集.,严格的来说是真超集.所以C语言当中的pth ...